This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
207 additions
and
26 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
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,47 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestSearchSimpleKeys(t *testing.T) { | ||
raw := []byte(`{ | ||
"alma": "mu", | ||
"name": "barack", | ||
"age": 12, | ||
"tags": ["good", "excellent", "ceu"] | ||
}`) | ||
tree, err := fromBytes(raw) | ||
if err != nil { | ||
t.Fatalf("failed to convert JSON to tree") | ||
} | ||
v, ok := tree.(*complexNode) | ||
if !ok { | ||
t.Fatalf("failed to convert tree to complexNode") | ||
} | ||
|
||
if len(v.data) != 4 { | ||
t.Fatalf("root element should have 4 children") | ||
} | ||
|
||
subtree, err := tree.search("alma") | ||
if err != nil { | ||
t.Fatalf("failed to search tree: %q", err.Error()) | ||
} | ||
if subtree == nil { | ||
t.Fatalf("subtree returned nil") | ||
} | ||
v2, ok := subtree.(*complexNode) | ||
if !ok { | ||
t.Fatalf("failed to convert tree to complexNode") | ||
} | ||
|
||
if len(v2.data) != 1 { | ||
t.Fatalf("searched subtree element should have 1 children") | ||
} | ||
anode, ok := v2.data["alma"] | ||
if !ok { | ||
t.Fatalf("first node should be alma node") | ||
} | ||
if anode.String(0, 0) != "\"mu\"" { | ||
t.Fatalf("searched subtree element should be mu. Instead it was %q", anode.String(0, 0)) | ||
} | ||
} |
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