summary refs log tree commit diff stats
path: root/tests/compilerapi
Commit message (Collapse)AuthorAgeFilesLines
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-1/+1
| | | | | | | | | | | | | | | | | | | * reworked ID handling * the packed AST now has its own ID mechanism * basic serialization code works * extract rodfiles to its own module * rodfiles: store and compare configs * rodfiles: store dependencies * store config at the end * precise dependency tracking * dependency tracking for rodfiles * completed loading of PSym, PType, etc * removed dead code * bugfix: do not realloc seqs when taking addr into an element * make IC opt-in for now * makes tcompilerapi green again * final cleanups Co-authored-by: Andy Davidoff <github@andy.disruptek.com>
* nimeval errorHook support (#15255)Scott Wadden2020-09-072-13/+29
|
* hotfix: make tcompilerapi green againAraq2020-04-301-2/+3
|
* make case-object transitions explicit, make unknownLineInfo a const, replace ↵Jasper Jenkins2020-01-171-1/+0
| | | | a few magic numbers with consts (#13170)
* make addQuoted work on nimscript (#12717) [backport]Jasper Jenkins2019-11-282-0/+6
|
* Fix spellings (#12277) [backport]Federico Ceratto2019-09-271-1/+1
|
* make tests green againAraq2019-05-271-0/+1
|
* fixes #1286; object case transitions are now soundAndreas Rumpf2019-05-271-0/+1
|
* megatest can be executedArne Döring2018-12-111-2/+1
|
* test case for #9180 and re-enables the disabled tcompilerapi test (#9181)Timothee Cour2018-10-111-22/+22
| | | | | | * add findNimStdLibCompileTime and un-disable tcompilerapi test; add test case for #9180 * address comments
* attempt to make travis green for 'koch testinstall'Andreas Rumpf2018-09-181-1/+8
|
* compiler API: final cleanups; improve security by diabling 'gorge' and friendsAndreas Rumpf2018-05-292-1/+14
|
* rewrote nimeval.nim; added tcompilerapi example to show how the compiler can ↵Andreas Rumpf2018-05-293-0/+46
be used as an API
lor: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Fields
const x = 5


# Test substring
static:
    assert "test".substring(3)   == "t"
    assert "test".substring(2,1) == "s"
    assert "test".substring(3,2) == "t"
    assert "test".substring(1,2) == "es"


# Various parsing tests
when true:

    block: #no_substitution
        proc actual: string = tmpli html"""
            <p>Test!</p>
        """
        const expected = html"""
            <p>Test!</p>
        """
        doAssert actual() == expected

    block: #basic
        proc actual: string = tmpli html"""
            <p>Test $$x</p>
            $x
        """
        const expected = html"""
            <p>Test $x</p>
            5
        """
        doAssert actual() == expected

    block: #expression
        proc actual: string = tmpli html"""
            <p>Test $$(x * 5)</p>
            $(x * 5)
        """
        const expected = html"""
            <p>Test $(x * 5)</p>
            25
        """
        doAssert actual() == expected

    block: #escape
        proc actual: string = tmpli js"""
            [{
                "hello world"
            }]
        """
        const expected = js"""
            [{
                "hello world"
            }]
        """
        doAssert actual() == expected

    block: #forIn
        proc actual: string = tmpli html"""
            <p>Test for</p>
            <ul>
                $for y in 0..2 {
                    <li>$y</li>
                }
            </ul>
        """
        const expected = html"""
            <p>Test for</p>
            <ul>
                <li>0</li>
                <li>1</li>
                <li>2</li>
            </ul>
        """
        doAssert actual() == expected

    block: #while
        proc actual: string = tmpli html"""
            <p>Test while/stmt</p>
            <ul>
                ${ var y = 0 }
                $while y < 4 {
                    <li>$y</li>
                    ${ inc(y) }
                }
            </ul>
        """
        const expected = html"""
            <p>Test while/stmt</p>
            <ul>
                <li>0</li>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        """
        doAssert actual() == expected

    block: #ifElifElse
        proc actual: string = tmpli html"""
            <p>Test if/elif/else</p>
            $if x == 8 {
                <div>x is 8!</div>
            }
            $elif x == 7 {
                <div>x is 7!</div>
            }
            $else {
                <div>x is neither!</div>
            }
        """
        const expected = html"""
            <p>Test if/elif/else</p>
            <div>x is neither!</div>
        """
        doAssert actual() == expected

    block: #multiLineStatements
        proc actual: string = tmpli html"""
            <p>Test multiline statements</p>
            ${
                var x = 5
                var y = 7
            }
            <span>$x</span><span>$y</span>
        """
        const expected = html"""
            <p>Test multiline statements</p>
            <span>5</span><span>7</span>
        """
        doAssert actual() == expected

    block: #caseOfElse
        proc actual: string = tmpli html"""
            <p>Test case</p>
            $case x
            $of 5 {
                <div>x == 5</div>
            }
            $of 6 {
                <div>x == 6</div>
            }
            $else {}
        """
        const expected = html"""
            <p>Test case</p>
            <div>x == 5</div>
        """
        doAssert actual() == expected



when true: #embeddingTest
    proc no_substitution: string = tmpli html"""
        <h1>Template test!</h1>
    """

    # # Single variable substitution
    proc substitution(who = "nobody"): string = tmpli html"""
        <div id="greeting">hello $who!</div>
    """

    # Expression template
    proc test_expression(nums: openarray[int] = []): string =
        var i = 2
        tmpli html"""
            $(no_substitution())
            $(substitution("Billy"))
            <div id="age">Age: $($nums[i] & "!!")</div>
        """

    proc test_statements(nums: openarray[int] = []): string =
        tmpli html"""
            $(test_expression(nums))
            $if true {
                <ul>
                    $for i in nums {
                        <li>$(i * 2)</li>
                    }
                </ul>
            }
        """

    var actual = test_statements([0,1,2])
    const expected = html"""
        <h1>Template test!</h1>
        <div id="greeting">hello Billy!</div>
        <div id="age">Age: 2!!</div>
        <ul>
            <li>0</li>
            <li>2</li>
            <li>4</li>
        </ul>
    """
    doAssert actual == expected


when defined(future):
    block: #tryCatch
        proc actual: string = tmpli html"""
            <p>Test try/catch</p>
            <div>
                $try {
                    <div>Lets try this!</div>
                }
                $except {
                    <div>Uh oh!</div>
                }
            </div>
        """
        const expected = html"""
            <p>Test try/catch</p>
            <div>
                    <div>Lets try this!</div>
            </div>
        """
        doAssert actual() == expected