summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/text/ParenthesisExpressionPrettyPrinterTest.java
blob: 79bdc6a53184698fa86a975f659b043090cf5dbc (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author bratseth
 */
public class ParenthesisExpressionPrettyPrinterTest {

    @Test
    public void testBasic() {
        String expected =
                "foo(\n" +
                "  bar(\n" +
                "    baz(\n" +
                "    )\n" +
                "  )\n" +
                ")\n";
        assertPrettyPrint(expected, "foo(bar(baz()))");
    }

    @Test
    public void testInnerContent() {
        String expected =
                "foo(\n" +
                "  bar(\n" +
                "    baz(\n" +
                "      hello world\n" +
                "    )\n" +
                "  )\n" +
                ")\n";
        assertPrettyPrint(expected, "foo(bar(baz(hello world)))");
    }
    @Test
    public void testUnmatchedStart() {
        String expected =
                "foo(\n" +
                "  (\n" +
                "    bar(\n" +
                "      baz(\n" +
                "      )\n" +
                "    )\n" +
                "  )\n" +
                "  ";
        assertPrettyPrint(expected, "foo((bar(baz()))");
    }

    @Test
    public void testUnmatchedEnd() {
        String expected =
                "foo(\n" +
                "  bar(\n" +
                "    baz(\n" +
                "    )\n" +
                "  )\n" +
                ")\n" +
                ")\n";
        assertPrettyPrint(expected, "foo(bar(baz())))");
    }

    @Test
    public void testNoParenthesis() {
        String expected =
                "foo bar baz";
        assertPrettyPrint(expected, "foo bar baz");
    }

    @Test
    public void testEmpty() {
        String expected =
                "";
        assertPrettyPrint(expected, "");
    }

    private void assertPrettyPrint(String expected, String expression) {
        assertEquals(expected, ParenthesisExpressionPrettyPrinter.prettyPrint(expression));
    }

}