Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix index out of range error * Add unit test for MakeNodeID; add fix
- Loading branch information
1 parent
bf3a0bd
commit c45f112
Showing
2 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ast | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMakeNodeID(t *testing.T) { | ||
tcs := []struct { | ||
id string | ||
port string | ||
want NodeID | ||
}{ | ||
{ // TC#1 | ||
id: "", | ||
port: "", | ||
want: NodeID{}}, | ||
{ // TC#2 | ||
id: "id", | ||
port: "p1", | ||
want: NodeID{"id", Port{"p1", ""}}, | ||
}, | ||
{ // TC#3 | ||
id: "_id", | ||
port: "p1:p2", | ||
want: NodeID{"_id", Port{"p1", "p2"}}, | ||
}, | ||
{ // TC#4 | ||
id: "1id", | ||
port: "p1:p2:p3", | ||
want: NodeID{"1id", Port{"p1", "p2"}}, | ||
}, | ||
{ // TC#5 | ||
id: "?id", | ||
port: ":p2:p3", | ||
want: NodeID{"?id", Port{"", "p2"}}, | ||
}, | ||
} | ||
|
||
for i, tc := range tcs { | ||
n := MakeNodeID(tc.id, tc.port) | ||
|
||
if *n != tc.want { | ||
t.Fatalf("TC#%d: MakeNodeId(%q, %q)=%#v, want %#v", i+1, tc.id, tc.port, *n, tc.want) | ||
} | ||
} | ||
} |