Skip to content

Commit

Permalink
+ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kniazkov committed Oct 29, 2024
1 parent 26a1a02 commit 523b8d0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ private AbstractNodeDescriptor parseAbstractNode(final String name, final Scanne
String.format("A vertical line '|' is expected after '%s'", subtype)
);
}
next = scanner.getToken();
} while (next != null);
if (zero && next != null) {
throw new NoTokensAfterZero(this.stmt.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cqfn.astranaut.parser;

import org.cqfn.astranaut.dsl.AbstractNodeDescriptor;
import org.cqfn.astranaut.dsl.ListNodeDescriptor;
import org.cqfn.astranaut.dsl.LiteralDescriptor;
import org.cqfn.astranaut.dsl.NodeDescriptor;
Expand Down Expand Up @@ -317,6 +318,70 @@ void literalWithExceptionButWithoutParser() {
Assertions.assertThrows(ParsingException.class, parser::parseDescriptor);
}

@Test
void regularNodeWithOneChild() {
final String code = "AAA <- BBB";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof RegularNodeDescriptor);
Assertions.assertEquals(code, descriptor.toString());
}

@Test
void regularNodeWithTwoChildren() {
final String code = "AAA <- BBB, CCC";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof RegularNodeDescriptor);
Assertions.assertEquals(code, descriptor.toString());
}

@Test
void regularNodeWithThreeChildren() {
final String code = "AAA <- BBB, CCC, DDD";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof RegularNodeDescriptor);
Assertions.assertEquals(code, descriptor.toString());
}

@Test
void regularNodeWithOptionalAndTaggedChildren() {
final String code = "AAA <- [BBB], ccc@CCC";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof RegularNodeDescriptor);
Assertions.assertEquals(code, descriptor.toString());
}

@Test
void abstractNodeWithTwoSubtypes() {
final String code = "AAA <- BBB | CCC";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof AbstractNodeDescriptor);
Assertions.assertEquals(code, descriptor.toString());
}

@Test
void abstractNodeWithThreeSubtypes() {
final String code = "AAA <- BBB | CCC | DDD";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof AbstractNodeDescriptor);
Assertions.assertEquals(code, descriptor.toString());
}

@Test
void abstractNodeWithZeroAtTheEnd() {
final String code = "AAA <- BBB | DDD | 0";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof AbstractNodeDescriptor);
Assertions.assertEquals("AAA <- BBB | DDD", descriptor.toString());
}

@Test
void abstractNodeWithOneSubtype() {
final String code = "AAA <- EEE | 0";
final NodeDescriptor descriptor = this.parseDescriptor(code);
Assertions.assertTrue(descriptor instanceof AbstractNodeDescriptor);
Assertions.assertEquals("AAA <- EEE | ?", descriptor.toString());
}

/**
* Parses a single descriptor from the DSL source code.
* @param code DSL source code
Expand Down

0 comments on commit 523b8d0

Please sign in to comment.