123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package urn
- import "strconv"
- type testCase struct {
- in string // the input
- ok bool // whether it is valid or not
- obj *URN // a pointer to the resulting urn.URN instance
- col int // the colum where the parsing error occurres
- tree string // the tree representation
- }
- var tests = []testCase{
- // ok
- {"urn:simple:simple", true, &URN{ID: "simple", SS: "simple"}, -1, "(urn urn : (iD simple) : (sS simple) <EOF>)"},
- // ok - RFC examples
- {"URN:foo:a123,456", true, &URN{ID: "foo", SS: "a123,456"}, -1, "(urn URN : (iD foo) : (sS a123,456) <EOF>)"},
- {"urn:foo:a123,456", true, &URN{ID: "foo", SS: "a123,456"}, -1, "(urn urn : (iD foo) : (sS a123,456) <EOF>)"},
- {"urn:FOO:a123,456", true, &URN{ID: "FOO", SS: "a123,456"}, -1, "(urn urn : (iD FOO) : (sS a123,456) <EOF>)"},
- {"urn:foo:A123,456", true, &URN{ID: "foo", SS: "A123,456"}, -1, "(urn urn : (iD foo) : (sS A123,456) <EOF>)"},
- {"urn:foo:a123%2C456", true, &URN{ID: "foo", SS: "a123%2C456"}, -1, "(urn urn : (iD foo) : (sS a123%2C456) <EOF>)"},
- {"URN:FOO:a123%2c456", true, &URN{ID: "FOO", SS: "a123%2c456"}, -1, "(urn URN : (iD FOO) : (sS a123%2c456) <EOF>)"},
- // ok - SCIM v2
- {"urn:ietf:params:scim:schemas:core:2.0:User", true, &URN{ID: "ietf", SS: "params:scim:schemas:core:2.0:User"}, -1, "(urn urn : (iD ietf) : (sS params : scim : schemas : core : 2.0 : User) <EOF>)"},
- {"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", true, &URN{ID: "ietf", SS: "params:scim:schemas:extension:enterprise:2.0:User"}, -1, "(urn urn : (iD ietf) : (sS params : scim : schemas : extension : enterprise : 2.0 : User) <EOF>)"},
- // ok - minimum urn
- {"urn:a:b", true, &URN{ID: "a", SS: "b"}, -1, "(urn urn : (iD a) : (sS b) <EOF>)"},
- {"urn:a::", true, &URN{ID: "a", SS: ":"}, -1, "(urn urn : (iD a) : (sS :) <EOF>)"},
- {"urn:a:-", true, &URN{ID: "a", SS: "-"}, -1, "(urn urn : (iD a) : (sS -) <EOF>)"},
- // ok - URN prefix is case-insensitive
- {"URN:simple:simple", true, &URN{ID: "simple", SS: "simple"}, -1, "(urn URN : (iD simple) : (sS simple) <EOF>)"},
- {"Urn:simple:simple", true, &URN{ID: "simple", SS: "simple"}, -1, "(urn Urn : (iD simple) : (sS simple) <EOF>)"},
- // ok - ID can contain the "urn" string but it can not be exactly equal to it
- {"urn:urna:simple", true, &URN{ID: "urna", SS: "simple"}, -1, "(urn urn : (iD urna) : (sS simple) <EOF>)"},
- {"urn:burnout:nss", true, &URN{ID: "burnout", SS: "nss"}, -1, "(urn urn : (iD burnout) : (sS nss) <EOF>)"},
- {"urn:burn:nss", true, &URN{ID: "burn", SS: "nss"}, -1, "(urn urn : (iD burn) : (sS nss) <EOF>)"},
- {"urn:urnurnurn:x", true, &URN{ID: "urnurnurn", SS: "x"}, -1, "(urn urn : (iD urnurnurn) : (sS x) <EOF>)"},
- // ok - ID can contains maximum 32 characters
- {"urn:abcdefghilmnopqrstuvzabcdefghilm:x", true, &URN{ID: "abcdefghilmnopqrstuvzabcdefghilm", SS: "x"}, 4 + 32, "(urn urn : (iD abcdefghilmnopqrstuvzabcdefghilm) : (sS x) <EOF>)"},
- // ok - ID can be alpha numeric
- {"URN:123:x", true, &URN{ID: "123", SS: "x"}, -1, "(urn URN : (iD 123) : (sS x) <EOF>)"},
- {"URN:1ab:x", true, &URN{ID: "1ab", SS: "x"}, -1, "(urn URN : (iD 1ab) : (sS x) <EOF>)"},
- {"URN:a1b:x", true, &URN{ID: "a1b", SS: "x"}, -1, "(urn URN : (iD a1b) : (sS x) <EOF>)"},
- {"URN:a12:x", true, &URN{ID: "a12", SS: "x"}, -1, "(urn URN : (iD a12) : (sS x) <EOF>)"},
- {"URN:cd2:x", true, &URN{ID: "cd2", SS: "x"}, -1, "(urn URN : (iD cd2) : (sS x) <EOF>)"},
- // ok - ID can contain an hyphen (not in its first position, see below)
- {"URN:abcd-:x", true, &URN{ID: "abcd-", SS: "x"}, -1, "(urn URN : (iD abcd-) : (sS x) <EOF>)"},
- {"URN:abcd-abcd:x", true, &URN{ID: "abcd-abcd", SS: "x"}, -1, "(urn URN : (iD abcd-abcd) : (sS x) <EOF>)"},
- {"URN:a123-456z:x", true, &URN{ID: "a123-456z", SS: "x"}, -1, "(urn URN : (iD a123-456z) : (sS x) <EOF>)"},
- // ok - SS can contain the "urn" string, also be exactly equal to it
- {"urn:urnx:urn", true, &URN{ID: "urnx", SS: "urn"}, -1, "(urn urn : (iD urnx) : (sS urn) <EOF>)"},
- {"urn:urnurnurn:urn", true, &URN{ID: "urnurnurn", SS: "urn"}, -1, "(urn urn : (iD urnurnurn) : (sS urn) <EOF>)"},
- {"urn:hey:urnurnurn", true, &URN{ID: "hey", SS: "urnurnurn"}, -1, "(urn urn : (iD hey) : (sS urnurnurn) <EOF>)"},
- // ok - SS can contains and discerns multiple colons, also at the end
- {"urn:ciao:a:b:c", true, &URN{ID: "ciao", SS: "a:b:c"}, -1, "(urn urn : (iD ciao) : (sS a : b : c) <EOF>)"},
- {"urn:aaa:x:y:", true, &URN{ID: "aaa", SS: "x:y:"}, -1, "(todo)"},
- {"urn:aaa:x:y:", true, &URN{ID: "aaa", SS: "x:y:"}, -1, "(todo)"},
- // ok - SS can contain (and also start with) some non-alphabetical (ie., OTHER) characters
- {"urn:ciao:-", true, &URN{ID: "ciao", SS: "-"}, -1, "(urn urn : (iD ciao) : (sS -) <EOF>)"},
- {"urn:ciao::", true, &URN{ID: "ciao", SS: ":"}, -1, "(urn urn : (iD ciao) : (sS :) <EOF>)"},
- {"urn:colon:::::nss", true, &URN{ID: "colon", SS: "::::nss"}, -1, "(todo)"},
- {"urn:ciao:!", true, &URN{ID: "ciao", SS: "!"}, -1, "(urn urn : (iD ciao) : (sS !) <EOF>)"},
- {"urn:ciao:!!*", true, &URN{ID: "ciao", SS: "!!*"}, -1, "(urn urn : (iD ciao) : (sS !!*) <EOF>)"},
- {"urn:ciao:-!:-,:x", true, &URN{ID: "ciao", SS: "-!:-,:x"}, -1, "(urn urn : (iD ciao) : (sS -!:-,:x) <EOF>)"},
- {"urn:ciao:=@", true, &URN{ID: "ciao", SS: "=@"}, -1, "(urn urn : (iD ciao) : (sS =@) <EOF>)"},
- {"urn:ciao:@!=(xyz)+a,b.*@g=$_'", true, &URN{ID: "ciao", SS: "@!=(xyz)+a,b.*@g=$_'"}, -1, "(urn urn : (iD ciao) : (sS @!=(xyz)+a,b.*@g=$_') <EOF>)"},
- // ok - SS can contain (and also start with) hexadecimal representation of octets
- {"URN:hexes:%25", true, &URN{ID: "hexes", SS: "%25"}, -1, "(urn urn : (iD hexes) : (sS %25) <EOF>)"}, // Literal use of the "%" character in a namespace must be encoded using "%25"
- {"URN:x:abc%1Dz%2F%3az", true, &URN{ID: "x", SS: "abc%1Dz%2F%3az"}, -1, "(urn urn : (iD x) : (sS abc%1Dz%2F%3az) <EOF>)"}, // Literal use of the "%" character in a namespace must be encoded using "%25"
- // no - ID can not start with an hyphen
- {"URN:-xxx:x", false, nil, 4, ""},
- {"URN:---xxx:x", false, nil, 4, ""},
- // no - ID can not start with a colon
- {"urn::colon:nss", false, nil, 4, ""},
- {"urn::::nss", false, nil, 4, ""},
- // no - ID can not contains more than 32 characters
- {"urn:abcdefghilmnopqrstuvzabcdefghilmn:specificstring", false, nil, 4 + 33, ""},
- // no - ID can not contain special characters
- {"URN:a!?:x", false, nil, 7, ""},
- {"URN:@,:x", false, nil, 6, ""},
- {"URN:#,:x", false, nil, 6, ""},
- {"URN:bc'.@:x", false, nil, 9, ""},
- // no - ID can not be equal to "urn"
- {"urn:urn:NSS", false, nil, 4, ""},
- // no - ID can not contain spaces
- {"urn:white space:NSS", false, nil, 9, ""},
- // no - SS can not contain spaces
- {"urn:concat:no spaces", false, nil, 13, ""},
- // no - SS can not contain reserved characters (can accept them only if %-escaped)
- {"urn:a:%", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"}, // the presence of an "%" character in an URN MUST be followed by two characters from the <hex> character set
- {"urn:a:?", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"},
- {"urn:a:#", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"},
- {"urn:a:/", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"},
- // no - Incomplete URNs
- {"urn:", false, nil, 4, ""},
- {"urn::", false, nil, 4, ""},
- {"urn:a", false, nil, 5, ""},
- {"urn:a:", false, nil, 6, ""},
- }
- func herror(index int, test testCase) string {
- return "Test case num. " + strconv.Itoa(index+1) + ", input \"" + test.in + "\""
- }
|