testingtable.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package urn
  2. import "strconv"
  3. type testCase struct {
  4. in string // the input
  5. ok bool // whether it is valid or not
  6. obj *URN // a pointer to the resulting urn.URN instance
  7. col int // the colum where the parsing error occurres
  8. tree string // the tree representation
  9. }
  10. var tests = []testCase{
  11. // ok
  12. {"urn:simple:simple", true, &URN{ID: "simple", SS: "simple"}, -1, "(urn urn : (iD simple) : (sS simple) <EOF>)"},
  13. // ok - RFC examples
  14. {"URN:foo:a123,456", true, &URN{ID: "foo", SS: "a123,456"}, -1, "(urn URN : (iD foo) : (sS a123,456) <EOF>)"},
  15. {"urn:foo:a123,456", true, &URN{ID: "foo", SS: "a123,456"}, -1, "(urn urn : (iD foo) : (sS a123,456) <EOF>)"},
  16. {"urn:FOO:a123,456", true, &URN{ID: "FOO", SS: "a123,456"}, -1, "(urn urn : (iD FOO) : (sS a123,456) <EOF>)"},
  17. {"urn:foo:A123,456", true, &URN{ID: "foo", SS: "A123,456"}, -1, "(urn urn : (iD foo) : (sS A123,456) <EOF>)"},
  18. {"urn:foo:a123%2C456", true, &URN{ID: "foo", SS: "a123%2C456"}, -1, "(urn urn : (iD foo) : (sS a123%2C456) <EOF>)"},
  19. {"URN:FOO:a123%2c456", true, &URN{ID: "FOO", SS: "a123%2c456"}, -1, "(urn URN : (iD FOO) : (sS a123%2c456) <EOF>)"},
  20. // ok - SCIM v2
  21. {"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>)"},
  22. {"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>)"},
  23. // ok - minimum urn
  24. {"urn:a:b", true, &URN{ID: "a", SS: "b"}, -1, "(urn urn : (iD a) : (sS b) <EOF>)"},
  25. {"urn:a::", true, &URN{ID: "a", SS: ":"}, -1, "(urn urn : (iD a) : (sS :) <EOF>)"},
  26. {"urn:a:-", true, &URN{ID: "a", SS: "-"}, -1, "(urn urn : (iD a) : (sS -) <EOF>)"},
  27. // ok - URN prefix is case-insensitive
  28. {"URN:simple:simple", true, &URN{ID: "simple", SS: "simple"}, -1, "(urn URN : (iD simple) : (sS simple) <EOF>)"},
  29. {"Urn:simple:simple", true, &URN{ID: "simple", SS: "simple"}, -1, "(urn Urn : (iD simple) : (sS simple) <EOF>)"},
  30. // ok - ID can contain the "urn" string but it can not be exactly equal to it
  31. {"urn:urna:simple", true, &URN{ID: "urna", SS: "simple"}, -1, "(urn urn : (iD urna) : (sS simple) <EOF>)"},
  32. {"urn:burnout:nss", true, &URN{ID: "burnout", SS: "nss"}, -1, "(urn urn : (iD burnout) : (sS nss) <EOF>)"},
  33. {"urn:burn:nss", true, &URN{ID: "burn", SS: "nss"}, -1, "(urn urn : (iD burn) : (sS nss) <EOF>)"},
  34. {"urn:urnurnurn:x", true, &URN{ID: "urnurnurn", SS: "x"}, -1, "(urn urn : (iD urnurnurn) : (sS x) <EOF>)"},
  35. // ok - ID can contains maximum 32 characters
  36. {"urn:abcdefghilmnopqrstuvzabcdefghilm:x", true, &URN{ID: "abcdefghilmnopqrstuvzabcdefghilm", SS: "x"}, 4 + 32, "(urn urn : (iD abcdefghilmnopqrstuvzabcdefghilm) : (sS x) <EOF>)"},
  37. // ok - ID can be alpha numeric
  38. {"URN:123:x", true, &URN{ID: "123", SS: "x"}, -1, "(urn URN : (iD 123) : (sS x) <EOF>)"},
  39. {"URN:1ab:x", true, &URN{ID: "1ab", SS: "x"}, -1, "(urn URN : (iD 1ab) : (sS x) <EOF>)"},
  40. {"URN:a1b:x", true, &URN{ID: "a1b", SS: "x"}, -1, "(urn URN : (iD a1b) : (sS x) <EOF>)"},
  41. {"URN:a12:x", true, &URN{ID: "a12", SS: "x"}, -1, "(urn URN : (iD a12) : (sS x) <EOF>)"},
  42. {"URN:cd2:x", true, &URN{ID: "cd2", SS: "x"}, -1, "(urn URN : (iD cd2) : (sS x) <EOF>)"},
  43. // ok - ID can contain an hyphen (not in its first position, see below)
  44. {"URN:abcd-:x", true, &URN{ID: "abcd-", SS: "x"}, -1, "(urn URN : (iD abcd-) : (sS x) <EOF>)"},
  45. {"URN:abcd-abcd:x", true, &URN{ID: "abcd-abcd", SS: "x"}, -1, "(urn URN : (iD abcd-abcd) : (sS x) <EOF>)"},
  46. {"URN:a123-456z:x", true, &URN{ID: "a123-456z", SS: "x"}, -1, "(urn URN : (iD a123-456z) : (sS x) <EOF>)"},
  47. // ok - SS can contain the "urn" string, also be exactly equal to it
  48. {"urn:urnx:urn", true, &URN{ID: "urnx", SS: "urn"}, -1, "(urn urn : (iD urnx) : (sS urn) <EOF>)"},
  49. {"urn:urnurnurn:urn", true, &URN{ID: "urnurnurn", SS: "urn"}, -1, "(urn urn : (iD urnurnurn) : (sS urn) <EOF>)"},
  50. {"urn:hey:urnurnurn", true, &URN{ID: "hey", SS: "urnurnurn"}, -1, "(urn urn : (iD hey) : (sS urnurnurn) <EOF>)"},
  51. // ok - SS can contains and discerns multiple colons, also at the end
  52. {"urn:ciao:a:b:c", true, &URN{ID: "ciao", SS: "a:b:c"}, -1, "(urn urn : (iD ciao) : (sS a : b : c) <EOF>)"},
  53. {"urn:aaa:x:y:", true, &URN{ID: "aaa", SS: "x:y:"}, -1, "(todo)"},
  54. {"urn:aaa:x:y:", true, &URN{ID: "aaa", SS: "x:y:"}, -1, "(todo)"},
  55. // ok - SS can contain (and also start with) some non-alphabetical (ie., OTHER) characters
  56. {"urn:ciao:-", true, &URN{ID: "ciao", SS: "-"}, -1, "(urn urn : (iD ciao) : (sS -) <EOF>)"},
  57. {"urn:ciao::", true, &URN{ID: "ciao", SS: ":"}, -1, "(urn urn : (iD ciao) : (sS :) <EOF>)"},
  58. {"urn:colon:::::nss", true, &URN{ID: "colon", SS: "::::nss"}, -1, "(todo)"},
  59. {"urn:ciao:!", true, &URN{ID: "ciao", SS: "!"}, -1, "(urn urn : (iD ciao) : (sS !) <EOF>)"},
  60. {"urn:ciao:!!*", true, &URN{ID: "ciao", SS: "!!*"}, -1, "(urn urn : (iD ciao) : (sS !!*) <EOF>)"},
  61. {"urn:ciao:-!:-,:x", true, &URN{ID: "ciao", SS: "-!:-,:x"}, -1, "(urn urn : (iD ciao) : (sS -!:-,:x) <EOF>)"},
  62. {"urn:ciao:=@", true, &URN{ID: "ciao", SS: "=@"}, -1, "(urn urn : (iD ciao) : (sS =@) <EOF>)"},
  63. {"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>)"},
  64. // ok - SS can contain (and also start with) hexadecimal representation of octets
  65. {"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"
  66. {"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"
  67. // no - ID can not start with an hyphen
  68. {"URN:-xxx:x", false, nil, 4, ""},
  69. {"URN:---xxx:x", false, nil, 4, ""},
  70. // no - ID can not start with a colon
  71. {"urn::colon:nss", false, nil, 4, ""},
  72. {"urn::::nss", false, nil, 4, ""},
  73. // no - ID can not contains more than 32 characters
  74. {"urn:abcdefghilmnopqrstuvzabcdefghilmn:specificstring", false, nil, 4 + 33, ""},
  75. // no - ID can not contain special characters
  76. {"URN:a!?:x", false, nil, 7, ""},
  77. {"URN:@,:x", false, nil, 6, ""},
  78. {"URN:#,:x", false, nil, 6, ""},
  79. {"URN:bc'.@:x", false, nil, 9, ""},
  80. // no - ID can not be equal to "urn"
  81. {"urn:urn:NSS", false, nil, 4, ""},
  82. // no - ID can not contain spaces
  83. {"urn:white space:NSS", false, nil, 9, ""},
  84. // no - SS can not contain spaces
  85. {"urn:concat:no spaces", false, nil, 13, ""},
  86. // no - SS can not contain reserved characters (can accept them only if %-escaped)
  87. {"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
  88. {"urn:a:?", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"},
  89. {"urn:a:#", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"},
  90. {"urn:a:/", false, nil, 5, "(urn urn : (iD a) : (sS %) <EOF>)"},
  91. // no - Incomplete URNs
  92. {"urn:", false, nil, 4, ""},
  93. {"urn::", false, nil, 4, ""},
  94. {"urn:a", false, nil, 5, ""},
  95. {"urn:a:", false, nil, 6, ""},
  96. }
  97. func herror(index int, test testCase) string {
  98. return "Test case num. " + strconv.Itoa(index+1) + ", input \"" + test.in + "\""
  99. }