1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
otto/cmpl_test.go
Steven Hartland 026a1d9a9c
chore: lint and naming refactor (#475)
Enable more linters, address the issues and do a major naming refactor
to use golang lower camelCase identifiers for types, functions, methods
and variable names.

Also: 
* Clean up inline generation so it doesn't rely on temporary variables.
* Remove unused functions generated by inline.pl.
2022-12-04 21:49:38 +00:00

54 lines
872 B
Go

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 := cmplParse(program)
value := vm.runtime.cmplEvaluateNodeProgram(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(cmplParse(program), "!=", nil)
}
test(``)
test(`var abc = 1; abc;`)
test(`
function abc() {
return;
}
`)
})
}