summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java
blob: 4a74324d873313f007a2201212c20e206bd96a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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"))
            ))
        );
    }
}