Skip to content

Commit

Permalink
Somewhat back to normal after context change.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Jul 21, 2017
1 parent a43cf34 commit f0a70fd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion expreduce/builtin_list.go
Expand Up @@ -11,7 +11,7 @@ func (this *Expression) ToStringList(form string, context *String, contextPath *
var buffer bytes.Buffer
buffer.WriteString("{")
for i, e := range this.Parts[1:] {
buffer.WriteString(e.String())
buffer.WriteString(e.StringForm(form, context, contextPath))
if i != len(this.Parts[1:])-1 {
buffer.WriteString(", ")
}
Expand Down
5 changes: 3 additions & 2 deletions expreduce/cas_test.go
Expand Up @@ -45,6 +45,7 @@ func TestIncludedModules(t *testing.T) {
if !testSymEx.MatchString(def.Name) {
continue
}
EvalInterp(fmt.Sprintf("$Context = \"%s%sTestState`\"", defSet.Name, def.Name), es)
def.AnnotateWithDynamic(es)
td := TestDesc{
module: defSet.Name,
Expand Down Expand Up @@ -149,10 +150,10 @@ func TestLowLevel(t *testing.T) {
assert.Equal(t, "(a * b * c * d * e * f)", EasyRun("a * b * c *d *e *f", es))

CasAssertSame(t, es, "2", "iubjndxuier = 2")
_, containsTest := es.defined["System`iubjndxuier"]
_, containsTest := es.defined["Global`iubjndxuier"]
assert.True(t, containsTest)
es.ClearAll()
_, containsTest = es.defined["System`iubjndxuier"]
_, containsTest = es.defined["Global`iubjndxuier"]
assert.False(t, containsTest)
}

Expand Down
5 changes: 2 additions & 3 deletions expreduce/evalstate.go
Expand Up @@ -161,10 +161,9 @@ func (es *EvalState) Init(loadAllDefs bool) {
data := MustAsset("resources/init.m")
EvalInterpMany(string(data), es)
}
//EvalInterp("$Context = \"Global`\"", es)
EvalInterp("$Context = \"Global`\"", es)
EvalInterp("$ContextPath = Append[$ContextPath, \"Global`\"]", es)
//EvalInterp("$ExpreduceContextStack = {\"Global`\"}", es)
EvalInterp("$ExpreduceContextStack = {\"System`\"}", es)
EvalInterp("$ExpreduceContextStack = {\"Global`\"}", es)
}

func NewEvalState() *EvalState {
Expand Down
2 changes: 1 addition & 1 deletion expreduce/ex_expression.go
Expand Up @@ -384,7 +384,7 @@ func (this *Expression) StringForm(form string, context *String, contextPath *Ex

// Default printing format
var buffer bytes.Buffer
buffer.WriteString(this.Parts[0].String())
buffer.WriteString(this.Parts[0].StringForm(form, context, contextPath))
buffer.WriteString("[")
for i, e := range this.Parts {
if i == 0 {
Expand Down
4 changes: 2 additions & 2 deletions expreduce/string.go
Expand Up @@ -47,10 +47,10 @@ func ToStringInfixAdvanced(parts []Ex, delim string, surroundEachArg bool, start
for i := 0; i < len(parts); i++ {
if surroundEachArg {
buffer.WriteString("(")
buffer.WriteString(parts[i].String())
buffer.WriteString(parts[i].StringForm(form, context, contextPath))
buffer.WriteString(")")
} else {
buffer.WriteString(parts[i].String())
buffer.WriteString(parts[i].StringForm(form, context, contextPath))
}
if i != len(parts)-1 {
buffer.WriteString(delim)
Expand Down
14 changes: 6 additions & 8 deletions expreduce/testing.go
Expand Up @@ -73,14 +73,12 @@ type SameTestEx struct {
}

func (this *SameTestEx) Run(t *testing.T, es *EvalState, td TestDesc) bool {
succ, s := CasTestInner(es, this.Out, this.In, this.In.String(), true, td.desc)
succ, s := CasTestInner(es, this.Out.Eval(es), this.In.Eval(es), this.In.String(), true, td.desc)
assert.True(t, succ, s)
return succ
}

func CasTestInner(es *EvalState, out Ex, in Ex, inStr string, test bool, desc string) (succ bool, s string) {
inTree := in.Eval(es)
outTree := out.Eval(es)
func CasTestInner(es *EvalState, inTree Ex, outTree Ex, inStr string, test bool, desc string) (succ bool, s string) {
theTestTree := NewExpression([]Ex{
&Symbol{"System`SameQ"},
NewExpression([]Ex{&Symbol{"System`Hold"}, inTree}),
Expand Down Expand Up @@ -117,25 +115,25 @@ func CasTestInner(es *EvalState, out Ex, in Ex, inStr string, test bool, desc st
}

func CasAssertSame(t *testing.T, es *EvalState, out string, in string) bool {
succ, s := CasTestInner(es, Interp(out, es), Interp(in, es), in, true, "")
succ, s := CasTestInner(es, Interp(in, es).Eval(es), Interp(out, es).Eval(es), in, true, "")
assert.True(t, succ, s)
return succ
}

func CasAssertDiff(t *testing.T, es *EvalState, out string, in string) bool {
succ, s := CasTestInner(es, Interp(out, es), Interp(in, es), in, false, "")
succ, s := CasTestInner(es, Interp(in, es).Eval(es), Interp(out, es).Eval(es), in, false, "")
assert.True(t, succ, s)
return succ
}

func CasAssertDescSame(t *testing.T, es *EvalState, out string, in string, desc string) bool {
succ, s := CasTestInner(es, Interp(out, es), Interp(in, es), in, true, desc)
succ, s := CasTestInner(es, Interp(in, es).Eval(es), Interp(out, es).Eval(es), in, true, desc)
assert.True(t, succ, s)
return succ
}

func CasAssertDescDiff(t *testing.T, es *EvalState, out string, in string, desc string) bool {
succ, s := CasTestInner(es, Interp(out, es), Interp(in, es), in, false, desc)
succ, s := CasTestInner(es, Interp(in, es).Eval(es), Interp(out, es).Eval(es), in, false, desc)
assert.True(t, succ, s)
return succ
}
2 changes: 1 addition & 1 deletion expreduce/testing_test.go
Expand Up @@ -12,7 +12,7 @@ func TestTesting(t *testing.T) {
es := NewEvalState()

CasAssertSame(t, es, " 1 ", " 1")
succ, s := CasTestInner(es, Interp(" 1. ", es), Interp("1 ", es), " 1. ", true, "")
succ, s := CasTestInner(es, Interp(" 1. ", es).Eval(es), Interp("1 ", es).Eval(es), " 1. ", true, "")
assert.False(t, succ, s)
CasAssertSame(t, es, "5.5", "1+1.5+3")
CasAssertDiff(t, es, "5.6", "1+1.5+3")
Expand Down

0 comments on commit f0a70fd

Please sign in to comment.