tables_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. package urn
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. func ierror(index int) string {
  7. return "Test case num. " + strconv.Itoa(index+1)
  8. }
  9. func herror(index int, test testCase) string {
  10. return ierror(index) + ", input \"" + string(test.in) + "\""
  11. }
  12. func rxpad(str string, lim int) string {
  13. str = str + strings.Repeat(" ", lim)
  14. return str[:lim]
  15. }
  16. type testCase struct {
  17. in []byte // the input
  18. ok bool // whether it is valid or not
  19. obj *URN // a pointer to the resulting urn.URN instance
  20. str string // string representation
  21. norm string // norm string representation
  22. estr string // error string
  23. }
  24. var urnlexTestCases = []testCase{
  25. // Italian act
  26. {
  27. []byte("urn:lex:it:stato:legge:2003-09-21;456"),
  28. true,
  29. &URN{
  30. prefix: "urn",
  31. ID: "lex",
  32. SS: "it:stato:legge:2003-09-21;456",
  33. },
  34. "urn:lex:it:stato:legge:2003-09-21;456",
  35. "urn:lex:it:stato:legge:2003-09-21;456",
  36. "",
  37. },
  38. // Italian decree
  39. // fixme(leodido)
  40. // verify whether it is correct or not that ~ is not accepted
  41. // does it requires RFC 8141 (issue #17) ?
  42. // {
  43. // []byte("urn:lex:it:ministero.giustizia:decreto:1992-07-24;358~art5"),
  44. // true,
  45. // &URN{
  46. // prefix: "urn",
  47. // ID: "lex",
  48. // SS: "it:ministero.giustizia:decreto:1992-07-24;358~art5",
  49. // },
  50. // "it:ministero.giustizia:decreto:1992-07-24;358~art5",
  51. // "it:ministero.giustizia:decreto:1992-07-24;358~art5",
  52. // "",
  53. // },
  54. // French act
  55. {
  56. []byte("urn:lex:fr:etat:lois:2004-12-06;321"),
  57. true,
  58. &URN{
  59. prefix: "urn",
  60. ID: "lex",
  61. SS: "fr:etat:lois:2004-12-06;321",
  62. },
  63. "urn:lex:fr:etat:lois:2004-12-06;321",
  64. "urn:lex:fr:etat:lois:2004-12-06;321",
  65. "",
  66. },
  67. // Spanish act
  68. {
  69. []byte("urn:lex:es:estado:ley:2002-07-12;123"),
  70. true,
  71. &URN{
  72. prefix: "urn",
  73. ID: "lex",
  74. SS: "es:estado:ley:2002-07-12;123",
  75. },
  76. "urn:lex:es:estado:ley:2002-07-12;123",
  77. "urn:lex:es:estado:ley:2002-07-12;123",
  78. "",
  79. },
  80. // Glarus Swiss Canton decree
  81. {
  82. []byte("urn:lex:ch;glarus:regiere:erlass:2007-10-15;963"),
  83. true,
  84. &URN{
  85. prefix: "urn",
  86. ID: "lex",
  87. SS: "ch;glarus:regiere:erlass:2007-10-15;963",
  88. },
  89. "urn:lex:ch;glarus:regiere:erlass:2007-10-15;963",
  90. "urn:lex:ch;glarus:regiere:erlass:2007-10-15;963",
  91. "",
  92. },
  93. // EU Council Directive
  94. {
  95. []byte("urn:lex:eu:council:directive:2010-03-09;2010-19-UE"),
  96. true,
  97. &URN{
  98. prefix: "urn",
  99. ID: "lex",
  100. SS: "eu:council:directive:2010-03-09;2010-19-UE",
  101. },
  102. "urn:lex:eu:council:directive:2010-03-09;2010-19-UE",
  103. "urn:lex:eu:council:directive:2010-03-09;2010-19-UE",
  104. "",
  105. },
  106. {
  107. []byte("urn:lex:eu:council:directive:2010-03-09;2010-19-UE"),
  108. true,
  109. &URN{
  110. prefix: "urn",
  111. ID: "lex",
  112. SS: "eu:council:directive:2010-03-09;2010-19-UE",
  113. },
  114. "urn:lex:eu:council:directive:2010-03-09;2010-19-UE",
  115. "urn:lex:eu:council:directive:2010-03-09;2010-19-UE",
  116. "",
  117. },
  118. // US FSC decision
  119. {
  120. []byte("urn:lex:us:federal.supreme.court:decision:1963-03-18;372.us.335"),
  121. true,
  122. &URN{
  123. prefix: "urn",
  124. ID: "lex",
  125. SS: "us:federal.supreme.court:decision:1963-03-18;372.us.335",
  126. },
  127. "urn:lex:us:federal.supreme.court:decision:1963-03-18;372.us.335",
  128. "urn:lex:us:federal.supreme.court:decision:1963-03-18;372.us.335",
  129. "",
  130. },
  131. }
  132. var genericTestCases = []testCase{
  133. // ok
  134. {
  135. []byte("urn:simple:simple"),
  136. true,
  137. &URN{
  138. prefix: "urn",
  139. ID: "simple",
  140. SS: "simple",
  141. },
  142. "urn:simple:simple",
  143. "urn:simple:simple",
  144. "",
  145. },
  146. {
  147. []byte("urn:ciao:%5D"),
  148. true,
  149. &URN{
  150. prefix: "urn",
  151. ID: "ciao",
  152. SS: "%5D",
  153. },
  154. "urn:ciao:%5D",
  155. "urn:ciao:%5d",
  156. "",
  157. },
  158. // ok - RFC examples
  159. {
  160. []byte("URN:foo:a123,456"),
  161. true,
  162. &URN{
  163. prefix: "URN",
  164. ID: "foo",
  165. SS: "a123,456",
  166. },
  167. "URN:foo:a123,456",
  168. "urn:foo:a123,456",
  169. "",
  170. },
  171. {
  172. []byte("urn:foo:a123,456"),
  173. true,
  174. &URN{
  175. prefix: "urn",
  176. ID: "foo",
  177. SS: "a123,456",
  178. },
  179. "urn:foo:a123,456",
  180. "urn:foo:a123,456",
  181. "",
  182. },
  183. {
  184. []byte("urn:FOO:a123,456"),
  185. true,
  186. &URN{
  187. prefix: "urn",
  188. ID: "FOO",
  189. SS: "a123,456",
  190. },
  191. "urn:FOO:a123,456",
  192. "urn:foo:a123,456",
  193. "",
  194. },
  195. {
  196. []byte("urn:foo:A123,456"),
  197. true,
  198. &URN{
  199. prefix: "urn",
  200. ID: "foo",
  201. SS: "A123,456",
  202. },
  203. "urn:foo:A123,456",
  204. "urn:foo:A123,456",
  205. "",
  206. },
  207. {
  208. []byte("urn:foo:a123%2C456"),
  209. true,
  210. &URN{
  211. prefix: "urn",
  212. ID: "foo",
  213. SS: "a123%2C456",
  214. },
  215. "urn:foo:a123%2C456",
  216. "urn:foo:a123%2c456",
  217. "",
  218. },
  219. {
  220. []byte("URN:FOO:a123%2c456"),
  221. true,
  222. &URN{
  223. prefix: "URN",
  224. ID: "FOO",
  225. SS: "a123%2c456",
  226. },
  227. "URN:FOO:a123%2c456",
  228. "urn:foo:a123%2c456",
  229. "",
  230. },
  231. {
  232. []byte("URN:FOO:ABC%FFabc123%2c456"),
  233. true,
  234. &URN{
  235. prefix: "URN",
  236. ID: "FOO",
  237. SS: "ABC%FFabc123%2c456",
  238. },
  239. "URN:FOO:ABC%FFabc123%2c456",
  240. "urn:foo:ABC%ffabc123%2c456",
  241. "",
  242. },
  243. {
  244. []byte("URN:FOO:ABC%FFabc123%2C456%9A"),
  245. true,
  246. &URN{
  247. prefix: "URN",
  248. ID: "FOO",
  249. SS: "ABC%FFabc123%2C456%9A",
  250. },
  251. "URN:FOO:ABC%FFabc123%2C456%9A",
  252. "urn:foo:ABC%ffabc123%2c456%9a",
  253. "",
  254. },
  255. // ok - SCIM v2
  256. {
  257. []byte("urn:ietf:params:scim:schemas:core:2.0:User"),
  258. true,
  259. &URN{
  260. prefix: "urn",
  261. ID: "ietf",
  262. SS: "params:scim:schemas:core:2.0:User",
  263. },
  264. "urn:ietf:params:scim:schemas:core:2.0:User",
  265. "urn:ietf:params:scim:schemas:core:2.0:User",
  266. "",
  267. },
  268. {
  269. []byte("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"),
  270. true,
  271. &URN{
  272. prefix: "urn",
  273. ID: "ietf",
  274. SS: "params:scim:schemas:extension:enterprise:2.0:User",
  275. },
  276. "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
  277. "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
  278. "",
  279. },
  280. {
  281. []byte("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:userName"),
  282. true,
  283. &URN{
  284. prefix: "urn",
  285. ID: "ietf",
  286. SS: "params:scim:schemas:extension:enterprise:2.0:User:userName",
  287. },
  288. "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:userName",
  289. "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:userName",
  290. "",
  291. },
  292. {
  293. []byte("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:meta.lastModified"),
  294. true,
  295. &URN{
  296. prefix: "urn",
  297. ID: "ietf",
  298. SS: "params:scim:schemas:extension:enterprise:2.0:User:meta.lastModified",
  299. },
  300. "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:meta.lastModified",
  301. "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:meta.lastModified",
  302. "",
  303. },
  304. // ok - minimum urn
  305. {
  306. []byte("urn:a:b"),
  307. true,
  308. &URN{
  309. prefix: "urn",
  310. ID: "a",
  311. SS: "b",
  312. },
  313. "urn:a:b",
  314. "urn:a:b",
  315. "",
  316. },
  317. {
  318. []byte("urn:a::"),
  319. true,
  320. &URN{
  321. prefix: "urn",
  322. ID: "a",
  323. SS: ":",
  324. },
  325. "urn:a::",
  326. "urn:a::",
  327. "",
  328. },
  329. {
  330. []byte("urn:a:-"),
  331. true,
  332. &URN{
  333. prefix: "urn",
  334. ID: "a",
  335. SS: "-",
  336. },
  337. "urn:a:-",
  338. "urn:a:-",
  339. "",
  340. },
  341. // ok - URN prefix is case-insensitive
  342. {
  343. []byte("URN:simple:simple"),
  344. true,
  345. &URN{
  346. prefix: "URN",
  347. ID: "simple",
  348. SS: "simple",
  349. },
  350. "URN:simple:simple",
  351. "urn:simple:simple",
  352. "",
  353. },
  354. {
  355. []byte("Urn:simple:simple"),
  356. true,
  357. &URN{
  358. prefix: "Urn",
  359. ID: "simple",
  360. SS: "simple",
  361. },
  362. "Urn:simple:simple",
  363. "urn:simple:simple",
  364. "",
  365. },
  366. // ok - ID can contain the "urn" string but it can not be exactly equal to it
  367. {
  368. []byte("urn:urna:simple"),
  369. true,
  370. &URN{
  371. prefix: "urn",
  372. ID: "urna",
  373. SS: "simple",
  374. },
  375. "urn:urna:simple",
  376. "urn:urna:simple",
  377. "",
  378. },
  379. {
  380. []byte("urn:burnout:nss"),
  381. true,
  382. &URN{
  383. prefix: "urn",
  384. ID: "burnout",
  385. SS: "nss",
  386. },
  387. "urn:burnout:nss",
  388. "urn:burnout:nss",
  389. "",
  390. },
  391. {
  392. []byte("urn:burn:nss"),
  393. true,
  394. &URN{
  395. prefix: "urn",
  396. ID: "burn",
  397. SS: "nss",
  398. },
  399. "urn:burn:nss",
  400. "urn:burn:nss",
  401. "",
  402. },
  403. {
  404. []byte("urn:urnurnurn:x"),
  405. true,
  406. &URN{
  407. prefix: "urn",
  408. ID: "urnurnurn",
  409. SS: "x",
  410. },
  411. "urn:urnurnurn:x",
  412. "urn:urnurnurn:x",
  413. "",
  414. },
  415. // ok - ID can contains maximum 32 characters
  416. {
  417. []byte("urn:abcdefghilmnopqrstuvzabcdefghilm:x"),
  418. true,
  419. &URN{
  420. prefix: "urn",
  421. ID: "abcdefghilmnopqrstuvzabcdefghilm",
  422. SS: "x",
  423. },
  424. "urn:abcdefghilmnopqrstuvzabcdefghilm:x",
  425. "urn:abcdefghilmnopqrstuvzabcdefghilm:x",
  426. "",
  427. },
  428. // ok - ID can be alpha numeric
  429. {
  430. []byte("URN:123:x"),
  431. true,
  432. &URN{
  433. prefix: "URN",
  434. ID: "123",
  435. SS: "x",
  436. },
  437. "URN:123:x",
  438. "urn:123:x",
  439. "",
  440. },
  441. {
  442. []byte("URN:1ab:x"),
  443. true,
  444. &URN{
  445. prefix: "URN",
  446. ID: "1ab",
  447. SS: "x",
  448. },
  449. "URN:1ab:x",
  450. "urn:1ab:x",
  451. "",
  452. },
  453. {
  454. []byte("URN:a1b:x"),
  455. true,
  456. &URN{
  457. prefix: "URN",
  458. ID: "a1b",
  459. SS: "x",
  460. },
  461. "URN:a1b:x",
  462. "urn:a1b:x",
  463. "",
  464. },
  465. {
  466. []byte("URN:a12:x"),
  467. true,
  468. &URN{
  469. prefix: "URN",
  470. ID: "a12",
  471. SS: "x",
  472. },
  473. "URN:a12:x",
  474. "urn:a12:x",
  475. "",
  476. },
  477. {
  478. []byte("URN:cd2:x"),
  479. true,
  480. &URN{
  481. prefix: "URN",
  482. ID: "cd2",
  483. SS: "x",
  484. },
  485. "URN:cd2:x",
  486. "urn:cd2:x",
  487. "",
  488. },
  489. // ok - ID can contain an hyphen (not in its first position, see below)
  490. {
  491. []byte("URN:abcd-:x"),
  492. true,
  493. &URN{
  494. prefix: "URN",
  495. ID: "abcd-",
  496. SS: "x",
  497. },
  498. "URN:abcd-:x",
  499. "urn:abcd-:x",
  500. "",
  501. },
  502. {
  503. []byte("URN:abcd-abcd:x"),
  504. true,
  505. &URN{
  506. prefix: "URN",
  507. ID: "abcd-abcd",
  508. SS: "x",
  509. },
  510. "URN:abcd-abcd:x",
  511. "urn:abcd-abcd:x",
  512. "",
  513. },
  514. {
  515. []byte("URN:a123-456z:x"),
  516. true,
  517. &URN{
  518. prefix: "URN",
  519. ID: "a123-456z",
  520. SS: "x",
  521. },
  522. "URN:a123-456z:x",
  523. "urn:a123-456z:x",
  524. "",
  525. },
  526. // ok - SS can contain the "urn" string, also be exactly equal to it
  527. {
  528. []byte("urn:urnx:urn"),
  529. true,
  530. &URN{
  531. prefix: "urn",
  532. ID: "urnx",
  533. SS: "urn",
  534. },
  535. "urn:urnx:urn",
  536. "urn:urnx:urn",
  537. "",
  538. },
  539. {
  540. []byte("urn:urnurnurn:urn"),
  541. true,
  542. &URN{
  543. prefix: "urn",
  544. ID: "urnurnurn",
  545. SS: "urn",
  546. },
  547. "urn:urnurnurn:urn",
  548. "urn:urnurnurn:urn",
  549. "",
  550. },
  551. {
  552. []byte("urn:hey:urnurnurn"),
  553. true,
  554. &URN{
  555. prefix: "urn",
  556. ID: "hey",
  557. SS: "urnurnurn",
  558. },
  559. "urn:hey:urnurnurn",
  560. "urn:hey:urnurnurn",
  561. "",
  562. },
  563. // ok - SS can contains and discerns multiple colons, also at the end
  564. {
  565. []byte("urn:ciao:a:b:c"),
  566. true,
  567. &URN{
  568. prefix: "urn",
  569. ID: "ciao",
  570. SS: "a:b:c",
  571. },
  572. "urn:ciao:a:b:c",
  573. "urn:ciao:a:b:c",
  574. "",
  575. },
  576. {
  577. []byte("urn:aaa:x:y:"),
  578. true,
  579. &URN{
  580. prefix: "urn",
  581. ID: "aaa",
  582. SS: "x:y:",
  583. },
  584. "urn:aaa:x:y:",
  585. "urn:aaa:x:y:",
  586. "",
  587. },
  588. {
  589. []byte("urn:aaa:x:y:"),
  590. true,
  591. &URN{
  592. prefix: "urn",
  593. ID: "aaa",
  594. SS: "x:y:",
  595. },
  596. "urn:aaa:x:y:",
  597. "urn:aaa:x:y:",
  598. "",
  599. },
  600. // ok - SS can contain (and also start with) some non-alphabetical (ie., OTHER) characters
  601. {
  602. []byte("urn:ciao:-"),
  603. true,
  604. &URN{
  605. prefix: "urn",
  606. ID: "ciao",
  607. SS: "-",
  608. },
  609. "urn:ciao:-",
  610. "urn:ciao:-",
  611. "",
  612. },
  613. {
  614. []byte("urn:ciao::"),
  615. true,
  616. &URN{
  617. prefix: "urn",
  618. ID: "ciao",
  619. SS: ":",
  620. },
  621. "urn:ciao::",
  622. "urn:ciao::",
  623. "",
  624. },
  625. {
  626. []byte("urn:colon:::::nss"),
  627. true,
  628. &URN{
  629. prefix: "urn",
  630. ID: "colon",
  631. SS: "::::nss",
  632. },
  633. "urn:colon:::::nss",
  634. "urn:colon:::::nss",
  635. "",
  636. },
  637. {
  638. []byte("urn:ciao:!"),
  639. true,
  640. &URN{
  641. prefix: "urn",
  642. ID: "ciao",
  643. SS: "!",
  644. },
  645. "urn:ciao:!",
  646. "urn:ciao:!",
  647. "",
  648. },
  649. {
  650. []byte("urn:ciao:!!*"),
  651. true,
  652. &URN{
  653. prefix: "urn",
  654. ID: "ciao",
  655. SS: "!!*",
  656. },
  657. "urn:ciao:!!*",
  658. "urn:ciao:!!*",
  659. "",
  660. },
  661. {
  662. []byte("urn:ciao:-!:-,:x"),
  663. true,
  664. &URN{
  665. prefix: "urn",
  666. ID: "ciao",
  667. SS: "-!:-,:x",
  668. },
  669. "urn:ciao:-!:-,:x",
  670. "urn:ciao:-!:-,:x",
  671. "",
  672. },
  673. {
  674. []byte("urn:ciao:=@"),
  675. true,
  676. &URN{
  677. prefix: "urn",
  678. ID: "ciao",
  679. SS: "=@",
  680. },
  681. "urn:ciao:=@",
  682. "urn:ciao:=@",
  683. "",
  684. },
  685. {
  686. []byte("urn:ciao:@!=%2C(xyz)+a,b.*@g=$_'"),
  687. true,
  688. &URN{
  689. prefix: "urn",
  690. ID: "ciao",
  691. SS: "@!=%2C(xyz)+a,b.*@g=$_'",
  692. },
  693. "urn:ciao:@!=%2C(xyz)+a,b.*@g=$_'",
  694. "urn:ciao:@!=%2c(xyz)+a,b.*@g=$_'",
  695. "",
  696. },
  697. // ok - SS can contain (and also start with) hexadecimal representation of octets
  698. {
  699. []byte("URN:hexes:%25"),
  700. true,
  701. &URN{
  702. prefix: "URN",
  703. ID: "hexes",
  704. SS: "%25",
  705. },
  706. "URN:hexes:%25",
  707. "urn:hexes:%25",
  708. "",
  709. }, // Literal use of the "%" character in a namespace must be encoded using "%25"
  710. {
  711. []byte("URN:x:abc%1Dz%2F%3az"),
  712. true,
  713. &URN{
  714. prefix: "URN",
  715. ID: "x",
  716. SS: "abc%1Dz%2F%3az",
  717. },
  718. "URN:x:abc%1Dz%2F%3az",
  719. "urn:x:abc%1dz%2f%3az",
  720. "",
  721. }, // Literal use of the "%" character in a namespace must be encoded using "%25"
  722. // no - ID can not start with an hyphen
  723. {
  724. []byte("URN:-xxx:x"),
  725. false,
  726. nil,
  727. "",
  728. "",
  729. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  730. },
  731. {
  732. []byte("URN:---xxx:x"),
  733. false,
  734. nil,
  735. "",
  736. "",
  737. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  738. },
  739. // no - ID can not start with a colon
  740. {
  741. []byte("urn::colon:nss"),
  742. false,
  743. nil,
  744. "",
  745. "",
  746. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  747. },
  748. {
  749. []byte("urn::::nss"),
  750. false,
  751. nil,
  752. "",
  753. "",
  754. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  755. },
  756. // no - ID can not contains more than 32 characters
  757. {
  758. []byte("urn:abcdefghilmnopqrstuvzabcdefghilmn:specificstring"),
  759. false,
  760. nil,
  761. "",
  762. "",
  763. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 36]`,
  764. },
  765. // no - ID can not contain special characters
  766. {
  767. []byte("URN:a!?:x"),
  768. false,
  769. nil,
  770. "",
  771. "",
  772. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 5]`,
  773. },
  774. {
  775. []byte("URN:@,:x"),
  776. false,
  777. nil,
  778. "",
  779. "",
  780. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  781. },
  782. {
  783. []byte("URN:#,:x"),
  784. false,
  785. nil,
  786. "",
  787. "",
  788. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  789. },
  790. {
  791. []byte("URN:bc'.@:x"),
  792. false,
  793. nil,
  794. "",
  795. "",
  796. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 6]`,
  797. },
  798. // no - ID can not be equal to "urn"
  799. {
  800. []byte("urn:urn:NSS"),
  801. false,
  802. nil,
  803. "",
  804. "",
  805. `expecting the identifier to not contain the "urn" reserved string [col 7]`,
  806. },
  807. {
  808. []byte("urn:URN:NSS"),
  809. false,
  810. nil,
  811. "",
  812. "",
  813. `expecting the identifier to not contain the "urn" reserved string [col 7]`,
  814. },
  815. {
  816. []byte("URN:URN:NSS"),
  817. false,
  818. nil,
  819. "",
  820. "",
  821. `expecting the identifier to not contain the "urn" reserved string [col 7]`,
  822. },
  823. {
  824. []byte("urn:UrN:NSS"),
  825. false,
  826. nil,
  827. "",
  828. "",
  829. `expecting the identifier to not contain the "urn" reserved string [col 7]`,
  830. },
  831. {
  832. []byte("urn:Urn:NSS"),
  833. false,
  834. nil,
  835. "",
  836. "",
  837. `expecting the identifier to not contain the "urn" reserved string [col 7]`,
  838. },
  839. // no - ID can not contain spaces
  840. {
  841. []byte("urn:white space:NSS"),
  842. false,
  843. nil,
  844. "",
  845. "",
  846. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 9]`,
  847. },
  848. // no - SS can not contain spaces
  849. {
  850. []byte("urn:concat:no spaces"),
  851. false,
  852. nil,
  853. "",
  854. "",
  855. `expecting the specific string to be a string containing alnum, hex, or others ([()+,-.:=@;$_!*']) chars [col 13]`,
  856. },
  857. // no - SS can not contain reserved characters (can accept them only if %-escaped)
  858. {
  859. []byte("urn:a:%"), // the presence of an "%" character in an URN MUST be followed by two characters from the <hex> character set
  860. false,
  861. nil,
  862. "",
  863. "",
  864. `expecting the specific string hex chars to be well-formed (%alnum{2}) [col 7]`,
  865. },
  866. {
  867. []byte("urn:a:?"),
  868. false,
  869. nil,
  870. "",
  871. "",
  872. `expecting the specific string to be a string containing alnum, hex, or others ([()+,-.:=@;$_!*']) chars [col 6]`,
  873. },
  874. {
  875. []byte("urn:a:#"),
  876. false,
  877. nil,
  878. "",
  879. "",
  880. `expecting the specific string to be a string containing alnum, hex, or others ([()+,-.:=@;$_!*']) chars [col 6]`,
  881. },
  882. {
  883. []byte("urn:a:/"),
  884. false,
  885. nil,
  886. "",
  887. "",
  888. `expecting the specific string to be a string containing alnum, hex, or others ([()+,-.:=@;$_!*']) chars [col 6]`,
  889. },
  890. // no - Incomplete URNs
  891. {
  892. []byte("urn:"),
  893. false,
  894. nil,
  895. "",
  896. "",
  897. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  898. },
  899. {
  900. []byte("urn::"),
  901. false,
  902. nil,
  903. "",
  904. "",
  905. `expecting the identifier to be string (1..31 alnum chars, also containing dashes but not at its start) [col 4]`,
  906. },
  907. {
  908. []byte("urn:a:"),
  909. false,
  910. nil,
  911. "",
  912. "",
  913. `expecting the specific string to be a string containing alnum, hex, or others ([()+,-.:=@;$_!*']) chars [col 6]`,
  914. },
  915. // {
  916. // "urn:a",
  917. // false,
  918. // nil,
  919. // "",
  920. // "",
  921. // "",
  922. // },
  923. }
  924. var equivalenceTests = []struct {
  925. eq bool
  926. lx []byte
  927. rx []byte
  928. }{
  929. {
  930. true,
  931. []byte("urn:foo:a123%2C456"),
  932. []byte("URN:FOO:a123%2c456"),
  933. },
  934. {
  935. true,
  936. []byte("urn:foo:AbC123%2C456"),
  937. []byte("URN:FOO:AbC123%2c456"),
  938. },
  939. {
  940. true,
  941. []byte("urn:foo:AbC123%2C456%1f"),
  942. []byte("URN:FOO:AbC123%2c456%1f"),
  943. },
  944. {
  945. true,
  946. []byte("URN:foo:a123,456"),
  947. []byte("urn:foo:a123,456"),
  948. },
  949. {
  950. true,
  951. []byte("URN:foo:a123,456"),
  952. []byte("urn:FOO:a123,456"),
  953. },
  954. {
  955. true,
  956. []byte("urn:foo:a123,456"),
  957. []byte("urn:FOO:a123,456"),
  958. },
  959. {
  960. true,
  961. []byte("urn:ciao:%2E"),
  962. []byte("urn:ciao:%2e"),
  963. },
  964. {
  965. false,
  966. []byte("urn:foo:A123,456"),
  967. []byte("URN:foo:a123,456"),
  968. },
  969. {
  970. false,
  971. []byte("urn:foo:A123,456"),
  972. []byte("urn:foo:a123,456"),
  973. },
  974. {
  975. false,
  976. []byte("urn:foo:A123,456"),
  977. []byte("urn:FOO:a123,456"),
  978. },
  979. }