@@ -23,6 +23,52 @@ import (
2323 "github.com/stretchr/testify/require"
2424)
2525
26+ const nestedFieldDocument = `{
27+ "@context": [
28+ {
29+ "@version": 1.1,
30+ "@protected": true,
31+ "id": "@id",
32+ "type": "@type",
33+ "CustomType": {
34+ "@id": "urn:uuid:79f824ba-fee3-11ed-be56-0242ac120002",
35+ "@context": {
36+ "@version": 1.1,
37+ "@protected": true,
38+ "@propagate": true,
39+ "id": "@id",
40+ "type": "@type",
41+ "xsd": "http://www.w3.org/2001/XMLSchema#",
42+ "customField": {
43+ "@id": "polygon-vocab:customField",
44+ "@type": "xsd:string"
45+ },
46+ "polygon-vocab": "urn:uuid:87caf7a2-fee3-11ed-be56-0242ac120001#",
47+ "objectField": {
48+ "@id": "polygon-vocab:objectField",
49+ "@context": {
50+ "@version": 1.1,
51+ "@protected": true,
52+ "id": "@id",
53+ "type": "@type",
54+ "customNestedField": {
55+ "@id": "polygon-vocab:customNestedField",
56+ "@type": "xsd:integer"
57+ }
58+ }
59+ }
60+ }
61+ }
62+ }
63+ ],
64+ "id": "urn:urn:e27a921e-fee5-11ed-be56-0242ac100000",
65+ "type": ["CustomType"],
66+ "customField": "1234",
67+ "objectField": {
68+ "customNestedField": 1
69+ }
70+ }`
71+
2672const testDocument = `{
2773 "@context": [
2874 "https://www.w3.org/2018/credentials/v1",
@@ -685,17 +731,31 @@ func TestFieldPathFromContext(t *testing.T) {
685731}
686732
687733func TestPathFromDocument (t * testing.T ) {
688- in := "credentialSubject.1.birthDate"
689- result , err := NewPathFromDocument ([]byte (testDocument ), in )
690- require .NoError (t , err )
734+ t .Run ("path with index array" , func (t * testing.T ) {
735+ in := "credentialSubject.1.birthDate"
736+ result , err := NewPathFromDocument ([]byte (testDocument ), in )
737+ require .NoError (t , err )
691738
692- want , err := NewPath (
693- "https://www.w3.org/2018/credentials#credentialSubject" ,
694- 1 ,
695- "http://schema.org/birthDate" )
696- require .NoError (t , err )
739+ want , err := NewPath (
740+ "https://www.w3.org/2018/credentials#credentialSubject" ,
741+ 1 ,
742+ "http://schema.org/birthDate" )
743+ require .NoError (t , err )
697744
698- require .Equal (t , want , result )
745+ require .Equal (t , want , result )
746+ })
747+
748+ t .Run ("path to nested field" , func (t * testing.T ) {
749+ path , err := NewPathFromDocument ([]byte (nestedFieldDocument ),
750+ "objectField.customNestedField" )
751+ require .NoError (t , err )
752+
753+ want , err := NewPath (
754+ "urn:uuid:87caf7a2-fee3-11ed-be56-0242ac120001#objectField" ,
755+ "urn:uuid:87caf7a2-fee3-11ed-be56-0242ac120001#customNestedField" )
756+ require .NoError (t , err )
757+ require .Equal (t , want , path )
758+ })
699759}
700760
701761func TestMkValueInt (t * testing.T ) {
0 commit comments