-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typemap reader refactored + unit test
- Loading branch information
Showing
2 changed files
with
59 additions
and
11 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,40 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"strings" | ||
) | ||
|
||
var testTypeMapStr = | ||
"Test1,*,*, GLType1,*,*\n" + | ||
"Test2,*,*, GLType2,*,*\n" + | ||
"Test3,*,*, GLType3,*,*\n" | ||
|
||
func checkType(tn, gltype string, tm TypeMap, t *testing.T) { | ||
if ty, ok := tm[tn]; ok { | ||
if ty == gltype { | ||
t.Logf("Type found: %v::%v", tn, gltype) | ||
return | ||
} | ||
t.Errorf("Type not found: %v::%v", tn, gltype) | ||
return | ||
} | ||
t.Errorf("Type not found: %v", tn) | ||
} | ||
|
||
func TestTypeMapReader(t *testing.T) { | ||
r := strings.NewReader(testTypeMapStr) | ||
tm, err := ReadTypeMap(r) | ||
if err != nil { | ||
t.Fatalf("Read type map failed: %v", err) | ||
} | ||
t.Logf("%v", tm) | ||
|
||
if len(tm) != 3 { | ||
t.Errorf("Wrong number of types.") | ||
} | ||
|
||
checkType("Test1", "GLType1", tm, t) | ||
checkType("Test2", "GLType2", tm, t) | ||
checkType("Test3", "GLType3", tm, t) | ||
} |