void Test(string source, string expectedResult) { Name.Init( ); SystemEnvironment.Init( ); try { Tokenizer lexer = new Tokenizer(new StringReader(source), "AstTest.cs/sample code"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); bool addSpace = false; do { Syntax result = SyntaxParser.Parse(lexer); if (result == null) { break; } var env = new Environment(SystemEnvironment.Top, EName.None, true); var ast = AstBuilder.Expand(result, env); if (addSpace) { sb.Append(" "); } else { addSpace = true; } sb.Append(Inspector.InspectObject(ast.GetDatum())); } while (lexer.LastToken != null); string sresult = sb.ToString(); Assert.AreEqual(expectedResult, sresult); } catch (BaseSchemeError ex) { Debug.LogError(string.Format("{0}\n{1}\n{2}", source, ex.Message, ex.StackTrace)); } Name.DeInit( ); }
private void OnValidate() { Name.Init( ); SystemEnvironment.Init( ); System.Text.StringBuilder sb; try { // ------------------------------------------------------------------ // Just tokenized it // ------------------------------------------------------------------ sb = new System.Text.StringBuilder(); lexer = new Tokenizer(new StringReader(testString), "AstTest"); var token = lexer.ReadToken(); while (token != null) { sb.Append(Inspector.InspectObject(token) + " "); token = lexer.ReadToken(); } tokensString = sb.ToString(); // ------------------------------------------------------------------ // Parse scheme // ------------------------------------------------------------------ lexer = new Tokenizer(new StringReader(testString), "AstTest"); sb = new System.Text.StringBuilder(); do { SObject result = SyntaxParser.Parse(lexer); if (result == null) { break; } sb.AppendLine(Inspector.InspectObject(result)); } while (lexer.LastToken != null); syntaxString = sb.ToString(); // ------------------------------------------------------------------ // Parse scheme // ------------------------------------------------------------------ lexer = new Tokenizer(new StringReader(testString), "AstTest"); sb = new System.Text.StringBuilder(); do { var result = SyntaxParser.Parse(lexer); if (result == null) { break; } var ast = AstBuilder.Expand(result, SystemEnvironment.Top); sb.AppendLine(Inspector.InspectObject(ast)); } while (lexer.LastToken != null); astString = sb.ToString(); envString = SystemEnvironment.Top.Inspect(); } catch (SchemeError ex) { astString = ex.Message; throw ex; } Name.DeInit( ); }