From f28f56b5f0df0ac0fb092b49522a5773c16d8b81 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 29 Jul 2017 23:48:01 -0700 Subject: [PATCH] Write basic tests for string matching. --- .../org/nwapw/abacus/tests/LexerTests.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/nwapw/abacus/tests/LexerTests.java b/src/test/java/org/nwapw/abacus/tests/LexerTests.java index 03fe1cb..66cb7ab 100644 --- a/src/test/java/org/nwapw/abacus/tests/LexerTests.java +++ b/src/test/java/org/nwapw/abacus/tests/LexerTests.java @@ -1,12 +1,31 @@ package org.nwapw.abacus.tests; +import org.junit.Assert; +import org.junit.Test; import org.nwapw.abacus.lexing.Lexer; -import org.nwapw.abacus.tree.TokenType; +import org.nwapw.abacus.lexing.pattern.Match; + +import java.util.List; public class LexerTests { - Lexer lexer = new Lexer(){{ + @Test + public void testBasicSuccess(){ + Lexer lexer = new Lexer<>(); + lexer.register("abc", 0); + lexer.register("def", 1); + List> matchedIntegers = lexer.lexAll("abcdefabc", 0, Integer::compare); + Assert.assertEquals(matchedIntegers.get(0).getType(), Integer.valueOf(0)); + Assert.assertEquals(matchedIntegers.get(1).getType(), Integer.valueOf(1)); + Assert.assertEquals(matchedIntegers.get(2).getType(), Integer.valueOf(0)); + } + + @Test + public void testBasicFailure(){ + Lexer lexer = new Lexer<>(); + lexer.register("abc", 0); + lexer.register("def", 1); + Assert.assertNull(lexer.lexAll("abcdefabcz", 0, Integer::compare)); + } - }}; - }