| 8 | ) |
| 9 | |
| 10 | func TestDefaultPathEncoder_EncodeDecode(t *testing.T) { |
| 11 | e := &defaultPathEncoder{} |
| 12 | |
| 13 | root := &Node{ |
| 14 | nodeName: "", |
| 15 | serializedNode: &persistencespb.ChasmNode{ |
| 16 | Metadata: &persistencespb.ChasmNodeMetadata{ |
| 17 | Attributes: &persistencespb.ChasmNodeMetadata_ComponentAttributes{ComponentAttributes: &persistencespb.ChasmComponentAttributes{}}, |
| 18 | }, |
| 19 | }, |
| 20 | } |
| 21 | child := &Node{ |
| 22 | parent: root, |
| 23 | nodeName: "child", |
| 24 | serializedNode: &persistencespb.ChasmNode{ |
| 25 | Metadata: &persistencespb.ChasmNodeMetadata{ |
| 26 | Attributes: &persistencespb.ChasmNodeMetadata_ComponentAttributes{ComponentAttributes: &persistencespb.ChasmComponentAttributes{}}, |
| 27 | }, |
| 28 | }, |
| 29 | } |
| 30 | collection := &Node{ |
| 31 | parent: root, |
| 32 | nodeName: "collection", |
| 33 | serializedNode: &persistencespb.ChasmNode{ |
| 34 | Metadata: &persistencespb.ChasmNodeMetadata{ |
| 35 | Attributes: &persistencespb.ChasmNodeMetadata_CollectionAttributes{CollectionAttributes: &persistencespb.ChasmCollectionAttributes{}}, |
| 36 | }, |
| 37 | }, |
| 38 | } |
| 39 | collectionItem := &Node{ |
| 40 | parent: collection, |
| 41 | nodeName: "item", |
| 42 | serializedNode: &persistencespb.ChasmNode{ |
| 43 | Metadata: &persistencespb.ChasmNodeMetadata{ |
| 44 | Attributes: &persistencespb.ChasmNodeMetadata_ComponentAttributes{ComponentAttributes: &persistencespb.ChasmComponentAttributes{}}, |
| 45 | }, |
| 46 | }, |
| 47 | } |
| 48 | collectionItemData := &Node{ |
| 49 | parent: collectionItem, |
| 50 | nodeName: "data", |
| 51 | serializedNode: &persistencespb.ChasmNode{ |
| 52 | Metadata: &persistencespb.ChasmNodeMetadata{ |
| 53 | Attributes: &persistencespb.ChasmNodeMetadata_DataAttributes{}, |
| 54 | }, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | tests := []struct { |
| 59 | node *Node |
| 60 | path []string |
| 61 | encoded string |
| 62 | }{ |
| 63 | {root, []string{}, ""}, |
| 64 | |
| 65 | {child, []string{"child"}, "child"}, |
| 66 | {child, []string{"special\\#"}, "special\\\\\\#"}, |
| 67 | {child, []string{" !"}, "\\ \\!"}, |