package org.zwobble.hobgoblin.compiler.parser; import org.junit.jupiter.api.Test; import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNodeMatcher.isUntypedDatabaseSchemaDefinitionNode; import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher.isUntypedTableDefinitionNode; import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.equalTo; import static org.zwobble.precisely.Matchers.isSequence; public class ParserDatabaseSchemaDefinitionTests { @Test public void emptySchema() { var source = """ databaseSchema BlogApp { }"""; var node = parseString( source, Parser::parseNamespaceStatement ); assertThat(node, isUntypedDatabaseSchemaDefinitionNode() .withName(equalTo("BlogApp")) .withBody(isSequence()) ); } @Test public void schemaWithStatements() { var source = """ databaseSchema BlogApp { table posts { row Post; primaryKey id; } table author { row Author; primaryKey id; } }"""; var node = parseString( source, Parser::parseNamespaceStatement ); assertThat(node, isUntypedDatabaseSchemaDefinitionNode() .withName(equalTo("BlogApp")) .withBody(isSequence( isUntypedTableDefinitionNode().withName(equalTo("posts")), isUntypedTableDefinitionNode().withName(equalTo("author")) )) ); } }