File: cmpl_test.go

package info (click to toggle)
golang-github-robertkrimen-otto 0.0~git20200922.ef014fd-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,796 kB
  • sloc: perl: 1,227; makefile: 79
file content (54 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (2)
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
package otto

import (
	"testing"

	"github.com/robertkrimen/otto/parser"
)

func Test_cmpl(t *testing.T) {
	tt(t, func() {
		vm := New()

		test := func(src string, expect ...interface{}) {
			program, err := parser.ParseFile(nil, "", src, 0)
			is(err, nil)
			{
				program := cmpl_parse(program)
				value := vm.runtime.cmpl_evaluate_nodeProgram(program, false)
				if len(expect) > 0 {
					is(value, expect[0])
				}
			}
		}

		test(``, Value{})

		test(`var abc = 1; abc;`, 1)

		test(`var abc = 1 + 1; abc;`, 2)

		test(`1 + 2;`, 3)
	})
}

func TestParse_cmpl(t *testing.T) {
	tt(t, func() {

		test := func(src string) {
			program, err := parser.ParseFile(nil, "", src, 0)
			is(err, nil)
			is(cmpl_parse(program), "!=", nil)
		}

		test(``)

		test(`var abc = 1; abc;`)

		test(`
            function abc() {
                return;
            }
        `)
	})
}