github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/state_test.go (about) 1 // Copyright 2011 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package nin 16 17 import ( 18 "testing" 19 ) 20 21 func TestState_Basic(t *testing.T) { 22 state := NewState() 23 24 command := EvalString{ 25 Parsed: []EvalStringToken{ 26 {"cat ", false}, 27 {"in", true}, 28 {" > ", false}, 29 {"out", true}, 30 }, 31 } 32 if got := command.Serialize(); got != "[cat ][$in][ > ][$out]" { 33 t.Fatal(got) 34 } 35 36 rule := NewRule("cat") 37 rule.Bindings["command"] = &command 38 state.Bindings.Rules[rule.Name] = rule 39 40 edge := state.addEdge(rule) 41 state.addIn(edge, "in1", 0) 42 state.addIn(edge, "in2", 0) 43 state.addOut(edge, "out", 0) 44 45 if got := edge.EvaluateCommand(false); got != "cat in1 in2 > out" { 46 t.Fatal(got) 47 } 48 49 if state.GetNode("in1", 0).Dirty { 50 t.Fatal("dirty") 51 } 52 if state.GetNode("in2", 0).Dirty { 53 t.Fatal("dirty") 54 } 55 if state.GetNode("out", 0).Dirty { 56 t.Fatal("dirty") 57 } 58 }