コード例 #1
0
		public void integersTest() {
			var errorManager = new CodeErrorManager();
			var scanner = new SourceCodeScanner(errorManager, "1 3".toCharArray());
			Assert.assertEquals(LexicalUnit.DecimalIntegerLiteral, scanner.nextLexicalUnit());
			Assert.assertEquals(1, scanner.EndPosition);
			Assert.assertEquals(LexicalUnit.Whitespace, scanner.nextLexicalUnit());
			Assert.assertEquals(2, scanner.EndPosition);
			Assert.assertEquals(LexicalUnit.DecimalIntegerLiteral, scanner.nextLexicalUnit());
			Assert.assertEquals(3, scanner.EndPosition);
		}
コード例 #2
0
		public void keywordTest() {
			var errorManager = new CodeErrorManager();
			var scanner = new SourceCodeScanner(errorManager, "class".toCharArray());
			Assert.assertEquals(LexicalUnit.Keyword, scanner.nextLexicalUnit());
			Assert.assertEquals(Keyword.Class, scanner.Keyword);
		}
コード例 #3
0
		private void doTest(String test) {
			var userDir = System.getProperty("user.dir");
			var sourcePath = PathHelper.combine(PathHelper.combine(userDir, "tests/resources/ParseExpressionTest/sources"), test + ".txt");
			var fileReader = new InputStreamReader(new FileInputStream((sourcePath)), Charset.forName("UTF-8"));
			var code = readToEnd(fileReader);
			text = code.toCharArray();
			var parser = new Parser();
			var scanner = new SourceCodeScanner(new CodeErrorManager(), text);
			var expression = parser.parseExpression(scanner);
			var result = expressionToString(expression);
			
			var generatedPath = PathHelper.combine(userDir, "tests/resources/ParseExpressionTest/generated");
			var generatedDir = new File(generatedPath);
			if (!generatedDir.exists()) {
				generatedDir.mkdir();
			}
			var fileWriter = new FileWriter(PathHelper.combine(generatedPath, test + ".txt"));
			fileWriter.write(result);
			fileWriter.close();
			
			var expectedPath = PathHelper.combine(userDir, "tests/resources/ParseExpressionTest/expected");
			var expectedFile = new File(PathHelper.combine(expectedPath, test + ".txt"));
			Assert.assertTrue("Expected file not found: " + expectedFile, expectedFile.exists());
			fileReader = new InputStreamReader(new FileInputStream((expectedFile)), Charset.forName("UTF-8"));
			var reference = readToEnd(fileReader);
			
			var genReader = new BufferedReader(new StringReader(result));
			var refReader = new BufferedReader(new StringReader(reference));
			for (;;) {
				var genLine = genReader.readLine();
				var refLine = refReader.readLine();
				if (genLine == null && refLine == null) {
					break;
				}
				Assert.assertEquals(refLine, genLine);
			}
		}