adding some eval tests
parent
0cad3a6253
commit
d4cc9761bd
@ -0,0 +1,62 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runEvalTest(t *testing.T, basepath, inpath, outpath string) {
|
||||
in, err := os.Open(inpath)
|
||||
if err != nil {
|
||||
t.Errorf("unable to open input file %s: %s", inpath, err)
|
||||
return
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Open(outpath)
|
||||
if err != nil {
|
||||
t.Errorf("unable to open output file %s: %s", outpath, err)
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
r_inpath := filepath.Base(inpath)
|
||||
n, err := strconv.ParseInt(strings.TrimSuffix(r_inpath, ".in"), 10, 64)
|
||||
if err != nil {
|
||||
t.Errorf("unable to get test number for path %s: %s", inpath, err)
|
||||
return
|
||||
}
|
||||
|
||||
inDoc, err := Read(in)
|
||||
if err != nil {
|
||||
t.Errorf("unable to read moon doc from infile: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
outDoc, err := Read(out)
|
||||
if err != nil {
|
||||
t.Errorf("unable to read moon doc from outfile: %s", err)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(inDoc, outDoc) {
|
||||
t.Errorf("test %d: input and output documents do not match!", n)
|
||||
t.Logf("input document: %v", inDoc)
|
||||
t.Logf("output document: %v", outDoc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEval(t *testing.T) {
|
||||
files, err := filepath.Glob("tests/eval/*.in")
|
||||
if err != nil {
|
||||
t.Errorf("unable to find test files: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, fname := range files {
|
||||
runEvalTest(t, "tests/eval/", fname, strings.Replace(fname, "in", "out", -1))
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
# a comment should evaluate to nothing
|
@ -0,0 +1,15 @@
|
||||
# simple keys and values
|
||||
|
||||
key: 1 # comments are stripped
|
||||
key_2: 2
|
||||
key_3: -1
|
||||
|
||||
# basically the stripping of comments is all we care about
|
||||
key_4: 0
|
||||
key_5: +0
|
||||
|
||||
key_6: this is a string
|
||||
key_7: "this is a quoted string"
|
||||
|
||||
key_8: [1 2 3]
|
||||
|
@ -0,0 +1,9 @@
|
||||
key: 1
|
||||
key_2: 2
|
||||
key_3: -1
|
||||
key_4: 0
|
||||
key_5: +0
|
||||
key_6: this is a string
|
||||
key_7: "this is a quoted string"
|
||||
key_8: [1 2 3]
|
||||
|
@ -0,0 +1,5 @@
|
||||
# now we test that variables actually work
|
||||
|
||||
key: this is a literal value
|
||||
another_key: @key
|
||||
|
@ -0,0 +1,2 @@
|
||||
key: this is a literal value
|
||||
another_key: this is a literal value
|
@ -0,0 +1,4 @@
|
||||
a_key: this is a value
|
||||
another_key: @a_key
|
||||
@var_key: this shouldn't ever be exported outside of the moon interpreter
|
||||
public_key: @var_key
|
@ -0,0 +1,25 @@
|
||||
root:
|
||||
assign:
|
||||
name:
|
||||
a_key
|
||||
value:
|
||||
string:
|
||||
this is a value
|
||||
assign:
|
||||
name:
|
||||
another_key
|
||||
value:
|
||||
variable:
|
||||
a_key
|
||||
assign:
|
||||
name:
|
||||
var_key
|
||||
value:
|
||||
string:
|
||||
this shouldn't ever be exported outside of the moon interpreter
|
||||
assign:
|
||||
name:
|
||||
public_key
|
||||
value:
|
||||
variable:
|
||||
var_key
|
Loading…
Reference in New Issue