package org.nwapw.abacus.tests; import org.junit.Assert; import org.junit.Test; import org.nwapw.abacus.lexing.Lexer; import org.nwapw.abacus.lexing.pattern.Match; import java.util.List; public class LexerTests { @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)); } @Test public void testNoPatterns(){ Lexer lexer = new Lexer<>(); Assert.assertNull(lexer.lexAll("abcdefabc", 0, Integer::compare)); } @Test public void testEmptyMatches(){ Lexer lexer = new Lexer<>(); lexer.register("a?", 0); Assert.assertNull(lexer.lexAll("", 0, Integer::compare)); } }