PageRenderTime 31ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/jruby-1.7.3/test/externals/ruby1.8/xsd/test_xsd.rb

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Ruby | 1511 lines | 1358 code | 145 blank | 8 comment | 2 complexity | 314aab7176db0f3827a45f41a9a7d6fd MD5 | raw file
  1. require 'test/unit'
  2. require 'xsd/datatypes'
  3. module XSD
  4. class TestXSD < Test::Unit::TestCase
  5. NegativeZero = (-1.0 / (1.0 / 0.0))
  6. def setup
  7. end
  8. def teardown
  9. end
  10. def assert_parsed_result(klass, str)
  11. o = klass.new(str)
  12. assert_equal(str, o.to_s)
  13. end
  14. def test_NSDBase
  15. o = XSD::NSDBase.new
  16. assert_equal(nil, o.type)
  17. end
  18. def test_XSDBase
  19. o = XSD::XSDAnySimpleType.new
  20. assert_equal(nil, o.data)
  21. assert_equal(true, o.is_nil)
  22. assert_equal('', o.to_s)
  23. end
  24. def test_XSDNil
  25. o = XSD::XSDNil.new
  26. assert_equal(XSD::Namespace, o.type.namespace)
  27. assert_equal(XSD::NilLiteral, o.type.name)
  28. assert_equal(nil, o.data)
  29. assert_equal(true, o.is_nil)
  30. o = XSD::XSDNil.new(nil)
  31. assert_equal(true, o.is_nil)
  32. assert_equal(nil, o.data)
  33. assert_equal("", o.to_s)
  34. o = XSD::XSDNil.new('var')
  35. assert_equal(false, o.is_nil)
  36. assert_equal('var', o.data)
  37. assert_equal('var', o.to_s)
  38. end
  39. def test_XSDString_UTF8
  40. o = XSD::XSDString.new
  41. assert_equal(XSD::Namespace, o.type.namespace)
  42. assert_equal(XSD::StringLiteral, o.type.name)
  43. assert_equal(nil, o.data)
  44. assert_equal(true, o.is_nil)
  45. str = "abc"
  46. assert_equal(str, XSD::XSDString.new(str).data)
  47. assert_equal(str, XSD::XSDString.new(str).to_s)
  48. assert_raises(XSD::ValueSpaceError) do
  49. XSD::XSDString.new("\0")
  50. end
  51. assert_raises(XSD::ValueSpaceError) do
  52. p XSD::XSDString.new("\xC0\xC0").to_s
  53. end
  54. end
  55. def test_XSDString_NONE
  56. XSD::Charset.module_eval { @encoding_backup = @encoding; @encoding = "NONE" }
  57. begin
  58. o = XSD::XSDString.new
  59. assert_equal(XSD::Namespace, o.type.namespace)
  60. assert_equal(XSD::StringLiteral, o.type.name)
  61. assert_equal(nil, o.data)
  62. assert_equal(true, o.is_nil)
  63. str = "abc"
  64. assert_equal(str, XSD::XSDString.new(str).data)
  65. assert_equal(str, XSD::XSDString.new(str).to_s)
  66. assert_raises(XSD::ValueSpaceError) do
  67. XSD::XSDString.new("\0")
  68. end
  69. assert_raises(XSD::ValueSpaceError) do
  70. p XSD::XSDString.new("\xC0\xC0").to_s
  71. end
  72. ensure
  73. XSD::Charset.module_eval { @encoding = @encoding_backup }
  74. end
  75. end
  76. def test_XSDBoolean
  77. o = XSD::XSDBoolean.new
  78. assert_equal(XSD::Namespace, o.type.namespace)
  79. assert_equal(XSD::BooleanLiteral, o.type.name)
  80. assert_equal(nil, o.data)
  81. assert_equal(true, o.is_nil)
  82. targets = [
  83. ["true", true],
  84. ["1", true],
  85. ["false", false],
  86. ["0", false],
  87. ]
  88. targets.each do |data, expected|
  89. assert_equal(expected, XSD::XSDBoolean.new(data).data)
  90. assert_equal(expected.to_s, XSD::XSDBoolean.new(data).to_s)
  91. end
  92. assert_raises(XSD::ValueSpaceError) do
  93. XSD::XSDBoolean.new("nil").to_s
  94. end
  95. end
  96. def test_XSDDecimal
  97. o = XSD::XSDDecimal.new
  98. assert_equal(XSD::Namespace, o.type.namespace)
  99. assert_equal(XSD::DecimalLiteral, o.type.name)
  100. assert_equal(nil, o.data)
  101. assert_equal(true, o.is_nil)
  102. targets = [
  103. 0,
  104. 1000000000,
  105. -9999999999,
  106. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
  107. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
  108. -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
  109. ]
  110. targets.each do |dec|
  111. assert_equal(dec.to_s, XSD::XSDDecimal.new(dec).data)
  112. end
  113. targets = [
  114. "0",
  115. "0.00000001",
  116. "1000000000",
  117. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  118. "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123.45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
  119. ]
  120. targets.each do |str|
  121. assert_equal(str, XSD::XSDDecimal.new(str).to_s)
  122. end
  123. targets = [
  124. ["-0", "0"],
  125. ["+0", "0"],
  126. ["0.0", "0"],
  127. ["-0.0", "0"],
  128. ["+0.0", "0"],
  129. ["0.", "0"],
  130. [".0", "0"],
  131. [
  132. "+0.12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  133. "0.1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
  134. ],
  135. [
  136. ".0000012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  137. "0.000001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
  138. ],
  139. [
  140. "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.",
  141. "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  142. ],
  143. ]
  144. targets.each do |data, expected|
  145. assert_equal(expected, XSD::XSDDecimal.new(data).to_s)
  146. end
  147. targets = [
  148. "0.000000000000a",
  149. "00a.0000000000001",
  150. "+-5",
  151. ]
  152. targets.each do |d|
  153. assert_raises(XSD::ValueSpaceError) do
  154. XSD::XSDDecimal.new(d)
  155. end
  156. end
  157. end
  158. def test_XSDFloat
  159. o = XSD::XSDFloat.new
  160. assert_equal(XSD::Namespace, o.type.namespace)
  161. assert_equal(XSD::FloatLiteral, o.type.name)
  162. assert_equal(nil, o.data)
  163. assert_equal(true, o.is_nil)
  164. targets = [
  165. 3.14159265358979,
  166. 12.34e36,
  167. 1.402e-45,
  168. -1.402e-45,
  169. ]
  170. targets.each do |f|
  171. assert_equal(f, XSD::XSDFloat.new(f).data)
  172. end
  173. targets = [
  174. "+3.141592654",
  175. "+1.234e+37",
  176. "+1.402e-45",
  177. "-1.402e-45",
  178. ]
  179. targets.each do |f|
  180. assert_equal(f, XSD::XSDFloat.new(f).to_s)
  181. end
  182. targets = [
  183. [3, "+3"], # should be 3.0?
  184. [-2, "-2"], # ditto
  185. [3.14159265358979, "+3.141592654"],
  186. [12.34e36, "+1.234e+37"],
  187. [1.402e-45, "+1.402e-45"],
  188. [-1.402e-45, "-1.402e-45"],
  189. ["1.402e", "+1.402"],
  190. ["12.34E36", "+1.234e+37"],
  191. ["1.402E-45", "+1.402e-45"],
  192. ["-1.402E-45", "-1.402e-45"],
  193. ["1.402E", "+1.402"],
  194. ]
  195. targets.each do |f, str|
  196. assert_equal(str, XSD::XSDFloat.new(f).to_s)
  197. end
  198. assert_equal("+0", XSD::XSDFloat.new(+0.0).to_s)
  199. assert_equal("-0", XSD::XSDFloat.new(NegativeZero).to_s)
  200. assert(XSD::XSDFloat.new(0.0/0.0).data.nan?)
  201. assert_equal("INF", XSD::XSDFloat.new(1.0/0.0).to_s)
  202. assert_equal(1, XSD::XSDFloat.new(1.0/0.0).data.infinite?)
  203. assert_equal("-INF", XSD::XSDFloat.new(-1.0/0.0).to_s)
  204. assert_equal(-1, XSD::XSDFloat.new(-1.0/0.0).data.infinite?)
  205. targets = [
  206. "0.000000000000a",
  207. "00a.0000000000001",
  208. "+-5",
  209. "5_0",
  210. ]
  211. targets.each do |d|
  212. assert_raises(XSD::ValueSpaceError) do
  213. XSD::XSDFloat.new(d)
  214. end
  215. end
  216. end
  217. def test_XSDDouble
  218. o = XSD::XSDDouble.new
  219. assert_equal(XSD::Namespace, o.type.namespace)
  220. assert_equal(XSD::DoubleLiteral, o.type.name)
  221. assert_equal(nil, o.data)
  222. assert_equal(true, o.is_nil)
  223. targets = [
  224. 3.14159265358979,
  225. 12.34e36,
  226. 1.402e-45,
  227. -1.402e-45,
  228. ]
  229. targets.each do |f|
  230. assert_equal(f, XSD::XSDDouble.new(f).data)
  231. end
  232. targets = [
  233. "+3.14159265358979",
  234. "+1.234e+37",
  235. "+1.402e-45",
  236. "-1.402e-45",
  237. ]
  238. targets.each do |f|
  239. assert_equal(f, XSD::XSDDouble.new(f).to_s)
  240. end
  241. targets = [
  242. [3, "+3"], # should be 3.0?
  243. [-2, "-2"], # ditto.
  244. [3.14159265358979, "+3.14159265358979"],
  245. [12.34e36, "+1.234e+37"],
  246. [1.402e-45, "+1.402e-45"],
  247. [-1.402e-45, "-1.402e-45"],
  248. ["1.402e", "+1.402"],
  249. ["12.34E36", "+1.234e+37"],
  250. ["1.402E-45", "+1.402e-45"],
  251. ["-1.402E-45", "-1.402e-45"],
  252. ["1.402E", "+1.402"],
  253. ]
  254. targets.each do |f, str|
  255. assert_equal(str, XSD::XSDDouble.new(f).to_s)
  256. end
  257. assert_equal("+0", XSD::XSDFloat.new(+0.0).to_s)
  258. assert_equal("-0", XSD::XSDFloat.new(NegativeZero).to_s)
  259. assert_equal("NaN", XSD::XSDDouble.new(0.0/0.0).to_s)
  260. assert(XSD::XSDDouble.new(0.0/0.0).data.nan?)
  261. assert_equal("INF", XSD::XSDDouble.new(1.0/0.0).to_s)
  262. assert_equal(1, XSD::XSDDouble.new(1.0/0.0).data.infinite?)
  263. assert_equal("-INF", XSD::XSDDouble.new(-1.0/0.0).to_s)
  264. assert_equal(-1, XSD::XSDDouble.new(-1.0/0.0).data.infinite?)
  265. targets = [
  266. "0.000000000000a",
  267. "00a.0000000000001",
  268. "+-5",
  269. ]
  270. targets.each do |d|
  271. assert_raises(XSD::ValueSpaceError) do
  272. XSD::XSDDouble.new(d)
  273. end
  274. end
  275. end
  276. def test_XSDDuration
  277. o = XSD::XSDDuration.new
  278. assert_equal(XSD::Namespace, o.type.namespace)
  279. assert_equal(XSD::DurationLiteral, o.type.name)
  280. assert_equal(nil, o.data)
  281. assert_equal(true, o.is_nil)
  282. targets = [
  283. "P1Y2M3DT4H5M6S",
  284. "P1234Y5678M9012DT3456H7890M1234.5678S",
  285. "P0DT3456H7890M1234.5678S",
  286. "P1234Y5678M9012D",
  287. "-P1234Y5678M9012DT3456H7890M1234.5678S",
  288. "P5678M9012DT3456H7890M1234.5678S",
  289. "-P1234Y9012DT3456H7890M1234.5678S",
  290. "+P1234Y5678MT3456H7890M1234.5678S",
  291. "P1234Y5678M9012DT7890M1234.5678S",
  292. "-P1234Y5678M9012DT3456H1234.5678S",
  293. "+P1234Y5678M9012DT3456H7890M",
  294. "P123400000000000Y",
  295. "-P567800000000000M",
  296. "+P901200000000000D",
  297. "P0DT345600000000000H",
  298. "-P0DT789000000000000M",
  299. "+P0DT123400000000000.000000000005678S",
  300. "P1234YT1234.5678S",
  301. "-P5678MT7890M",
  302. "+P9012DT3456H",
  303. ]
  304. targets.each do |str|
  305. assert_parsed_result(XSD::XSDDuration, str)
  306. end
  307. targets = [
  308. ["P0Y0M0DT0H0M0S",
  309. "P0D"],
  310. ["-P0DT0S",
  311. "-P0D"],
  312. ["P01234Y5678M9012DT3456H7890M1234.5678S",
  313. "P1234Y5678M9012DT3456H7890M1234.5678S"],
  314. ["P1234Y005678M9012DT3456H7890M1234.5678S",
  315. "P1234Y5678M9012DT3456H7890M1234.5678S"],
  316. ["P1234Y5678M0009012DT3456H7890M1234.5678S",
  317. "P1234Y5678M9012DT3456H7890M1234.5678S"],
  318. ["P1234Y5678M9012DT00003456H7890M1234.5678S",
  319. "P1234Y5678M9012DT3456H7890M1234.5678S"],
  320. ["P1234Y5678M9012DT3456H000007890M1234.5678S",
  321. "P1234Y5678M9012DT3456H7890M1234.5678S"],
  322. ["P1234Y5678M9012DT3456H7890M0000001234.5678S",
  323. "P1234Y5678M9012DT3456H7890M1234.5678S"],
  324. ]
  325. targets.each do |data, expected|
  326. assert_equal(expected, XSD::XSDDuration.new(data).to_s)
  327. end
  328. end
  329. def test_XSDDateTime
  330. o = XSD::XSDDateTime.new
  331. assert_equal(XSD::Namespace, o.type.namespace)
  332. assert_equal(XSD::DateTimeLiteral, o.type.name)
  333. assert_equal(nil, o.data)
  334. assert_equal(true, o.is_nil)
  335. targets = [
  336. "2002-05-18T16:52:20Z",
  337. "0001-01-01T00:00:00Z",
  338. "9999-12-31T23:59:59Z",
  339. "19999-12-31T23:59:59Z",
  340. "2002-12-31T23:59:59.999Z",
  341. "2002-12-31T23:59:59.001Z",
  342. "2002-12-31T23:59:59.99999999999999999999Z",
  343. "2002-12-31T23:59:59.00000000000000000001Z",
  344. "2002-12-31T23:59:59+09:00",
  345. "2002-12-31T23:59:59+00:01",
  346. "2002-12-31T23:59:59-00:01",
  347. "2002-12-31T23:59:59-23:59",
  348. "2002-12-31T23:59:59.00000000000000000001+13:30",
  349. "2002-12-31T23:59:59.5137Z",
  350. "2002-12-31T23:59:59.51375Z", # 411/800
  351. "2002-12-31T23:59:59.51375+12:34",
  352. "-2002-05-18T16:52:20Z",
  353. "-4713-01-01T12:00:00Z",
  354. "-2002-12-31T23:59:59+00:01",
  355. "-0001-12-31T23:59:59.00000000000000000001+13:30",
  356. ]
  357. targets.each do |str|
  358. assert_parsed_result(XSD::XSDDateTime, str)
  359. end
  360. targets = [
  361. ["2002-12-31T23:59:59.00",
  362. "2002-12-31T23:59:59Z"],
  363. ["2002-12-31T23:59:59+00:00",
  364. "2002-12-31T23:59:59Z"],
  365. ["2002-12-31T23:59:59-00:00",
  366. "2002-12-31T23:59:59Z"],
  367. ["-2002-12-31T23:59:59.00",
  368. "-2002-12-31T23:59:59Z"],
  369. ["-2002-12-31T23:59:59+00:00",
  370. "-2002-12-31T23:59:59Z"],
  371. ["-2002-12-31T23:59:59-00:00",
  372. "-2002-12-31T23:59:59Z"],
  373. ]
  374. targets.each do |data, expected|
  375. assert_equal(expected, XSD::XSDDateTime.new(data).to_s)
  376. d = DateTime.parse(data)
  377. d >>= 12 if d.year < 0 # XSDDateTime.year(-1) == DateTime.year(0)
  378. assert_equal(expected, XSD::XSDDateTime.new(d).to_s)
  379. end
  380. targets = [
  381. "0000-05-18T16:52:20Z",
  382. "05-18T16:52:20Z",
  383. "2002-05T16:52:20Z",
  384. "2002-05-18T16:52Z",
  385. "",
  386. ]
  387. targets.each do |d|
  388. assert_raises(XSD::ValueSpaceError, d.to_s) do
  389. XSD::XSDDateTime.new(d)
  390. end
  391. end
  392. end
  393. def test_XSDTime
  394. o = XSD::XSDTime.new
  395. assert_equal(XSD::Namespace, o.type.namespace)
  396. assert_equal(XSD::TimeLiteral, o.type.name)
  397. assert_equal(nil, o.data)
  398. assert_equal(true, o.is_nil)
  399. targets = [
  400. "16:52:20Z",
  401. "00:00:00Z",
  402. "23:59:59Z",
  403. "23:59:59.999Z",
  404. "23:59:59.001Z",
  405. "23:59:59.99999999999999999999Z",
  406. "23:59:59.00000000000000000001Z",
  407. "23:59:59+09:00",
  408. "23:59:59+00:01",
  409. "23:59:59-00:01",
  410. "23:59:59-23:59",
  411. "23:59:59.00000000000000000001+13:30",
  412. "23:59:59.51345Z",
  413. "23:59:59.51345+12:34",
  414. "23:59:59+00:01",
  415. ]
  416. targets.each do |str|
  417. assert_parsed_result(XSD::XSDTime, str)
  418. end
  419. targets = [
  420. ["23:59:59.00",
  421. "23:59:59Z"],
  422. ["23:59:59+00:00",
  423. "23:59:59Z"],
  424. ["23:59:59-00:00",
  425. "23:59:59Z"],
  426. ]
  427. targets.each do |data, expected|
  428. assert_equal(expected, XSD::XSDTime.new(data).to_s)
  429. end
  430. end
  431. def test_XSDDate
  432. o = XSD::XSDDate.new
  433. assert_equal(XSD::Namespace, o.type.namespace)
  434. assert_equal(XSD::DateLiteral, o.type.name)
  435. assert_equal(nil, o.data)
  436. assert_equal(true, o.is_nil)
  437. targets = [
  438. "2002-05-18Z",
  439. "0001-01-01Z",
  440. "9999-12-31Z",
  441. "19999-12-31Z",
  442. "2002-12-31+09:00",
  443. "2002-12-31+00:01",
  444. "2002-12-31-00:01",
  445. "2002-12-31-23:59",
  446. "2002-12-31+13:30",
  447. "-2002-05-18Z",
  448. "-19999-12-31Z",
  449. "-2002-12-31+00:01",
  450. "-0001-12-31+13:30",
  451. ]
  452. targets.each do |str|
  453. assert_parsed_result(XSD::XSDDate, str)
  454. end
  455. targets = [
  456. ["2002-12-31",
  457. "2002-12-31Z"],
  458. ["2002-12-31+00:00",
  459. "2002-12-31Z"],
  460. ["2002-12-31-00:00",
  461. "2002-12-31Z"],
  462. ["-2002-12-31",
  463. "-2002-12-31Z"],
  464. ["-2002-12-31+00:00",
  465. "-2002-12-31Z"],
  466. ["-2002-12-31-00:00",
  467. "-2002-12-31Z"],
  468. ]
  469. targets.each do |data, expected|
  470. assert_equal(expected, XSD::XSDDate.new(data).to_s)
  471. d = Date.parse(data)
  472. d >>= 12 if d.year < 0 # XSDDate.year(-1) == Date.year(0)
  473. assert_equal(expected, XSD::XSDDate.new(d).to_s)
  474. end
  475. end
  476. end
  477. class TestXSD2 < Test::Unit::TestCase
  478. def setup
  479. # Nothing to do.
  480. end
  481. def teardown
  482. # Nothing to do.
  483. end
  484. def assert_parsed_result(klass, str)
  485. o = klass.new(str)
  486. assert_equal(str, o.to_s)
  487. end
  488. def test_XSDGYearMonth
  489. o = XSD::XSDGYearMonth.new
  490. assert_equal(XSD::Namespace, o.type.namespace)
  491. assert_equal(XSD::GYearMonthLiteral, o.type.name)
  492. assert_equal(nil, o.data)
  493. assert_equal(true, o.is_nil)
  494. targets = [
  495. "2002-05Z",
  496. "0001-01Z",
  497. "9999-12Z",
  498. "19999-12Z",
  499. "2002-12+09:00",
  500. "2002-12+00:01",
  501. "2002-12-00:01",
  502. "2002-12-23:59",
  503. "2002-12+13:30",
  504. "-2002-05Z",
  505. "-19999-12Z",
  506. "-2002-12+00:01",
  507. "-0001-12+13:30",
  508. ]
  509. targets.each do |str|
  510. assert_parsed_result(XSD::XSDGYearMonth, str)
  511. end
  512. targets = [
  513. ["2002-12",
  514. "2002-12Z"],
  515. ["2002-12+00:00",
  516. "2002-12Z"],
  517. ["2002-12-00:00",
  518. "2002-12Z"],
  519. ["-2002-12",
  520. "-2002-12Z"],
  521. ["-2002-12+00:00",
  522. "-2002-12Z"],
  523. ["-2002-12-00:00",
  524. "-2002-12Z"],
  525. ]
  526. targets.each do |data, expected|
  527. assert_equal(expected, XSD::XSDGYearMonth.new(data).to_s)
  528. end
  529. end
  530. def test_XSDGYear
  531. o = XSD::XSDGYear.new
  532. assert_equal(XSD::Namespace, o.type.namespace)
  533. assert_equal(XSD::GYearLiteral, o.type.name)
  534. assert_equal(nil, o.data)
  535. assert_equal(true, o.is_nil)
  536. targets = [
  537. "2002Z",
  538. "0001Z",
  539. "9999Z",
  540. "19999Z",
  541. "2002+09:00",
  542. "2002+00:01",
  543. "2002-00:01",
  544. "2002-23:59",
  545. "2002+13:30",
  546. "-2002Z",
  547. "-19999Z",
  548. "-2002+00:01",
  549. "-0001+13:30",
  550. ]
  551. targets.each do |str|
  552. assert_parsed_result(XSD::XSDGYear, str)
  553. end
  554. targets = [
  555. ["2002",
  556. "2002Z"],
  557. ["2002+00:00",
  558. "2002Z"],
  559. ["2002-00:00",
  560. "2002Z"],
  561. ["-2002",
  562. "-2002Z"],
  563. ["-2002+00:00",
  564. "-2002Z"],
  565. ["-2002-00:00",
  566. "-2002Z"],
  567. ]
  568. targets.each do |data, expected|
  569. assert_equal(expected, XSD::XSDGYear.new(data).to_s)
  570. end
  571. end
  572. def test_XSDGMonthDay
  573. o = XSD::XSDGMonthDay.new
  574. assert_equal(XSD::Namespace, o.type.namespace)
  575. assert_equal(XSD::GMonthDayLiteral, o.type.name)
  576. assert_equal(nil, o.data)
  577. assert_equal(true, o.is_nil)
  578. targets = [
  579. "05-18Z",
  580. "01-01Z",
  581. "12-31Z",
  582. "12-31+09:00",
  583. "12-31+00:01",
  584. "12-31-00:01",
  585. "12-31-23:59",
  586. "12-31+13:30",
  587. ]
  588. targets.each do |str|
  589. assert_parsed_result(XSD::XSDGMonthDay, str)
  590. end
  591. targets = [
  592. ["12-31",
  593. "12-31Z"],
  594. ["12-31+00:00",
  595. "12-31Z"],
  596. ["12-31-00:00",
  597. "12-31Z"],
  598. ]
  599. targets.each do |data, expected|
  600. assert_equal(expected, XSD::XSDGMonthDay.new(data).to_s)
  601. end
  602. end
  603. def test_XSDGDay
  604. o = XSD::XSDGDay.new
  605. assert_equal(XSD::Namespace, o.type.namespace)
  606. assert_equal(XSD::GDayLiteral, o.type.name)
  607. assert_equal(nil, o.data)
  608. assert_equal(true, o.is_nil)
  609. targets = [
  610. "18Z",
  611. "01Z",
  612. "31Z",
  613. "31+09:00",
  614. "31+00:01",
  615. "31-00:01",
  616. "31-23:59",
  617. "31+13:30",
  618. ]
  619. targets.each do |str|
  620. assert_parsed_result(XSD::XSDGDay, str)
  621. end
  622. targets = [
  623. ["31",
  624. "31Z"],
  625. ["31+00:00",
  626. "31Z"],
  627. ["31-00:00",
  628. "31Z"],
  629. ]
  630. targets.each do |data, expected|
  631. assert_equal(expected, XSD::XSDGDay.new(data).to_s)
  632. end
  633. end
  634. def test_XSDGMonth
  635. o = XSD::XSDGMonth.new
  636. assert_equal(XSD::Namespace, o.type.namespace)
  637. assert_equal(XSD::GMonthLiteral, o.type.name)
  638. assert_equal(nil, o.data)
  639. assert_equal(true, o.is_nil)
  640. targets = [
  641. "05Z",
  642. "01Z",
  643. "12Z",
  644. "12+09:00",
  645. "12+00:01",
  646. "12-00:01",
  647. "12-23:59",
  648. "12+13:30",
  649. ]
  650. targets.each do |str|
  651. assert_parsed_result(XSD::XSDGMonth, str)
  652. end
  653. targets = [
  654. ["12",
  655. "12Z"],
  656. ["12+00:00",
  657. "12Z"],
  658. ["12-00:00",
  659. "12Z"],
  660. ]
  661. targets.each do |data, expected|
  662. assert_equal(expected, XSD::XSDGMonth.new(data).to_s)
  663. end
  664. end
  665. def test_XSDHexBinary
  666. o = XSD::XSDHexBinary.new
  667. assert_equal(XSD::Namespace, o.type.namespace)
  668. assert_equal(XSD::HexBinaryLiteral, o.type.name)
  669. assert_equal(nil, o.data)
  670. assert_equal(true, o.is_nil)
  671. targets = [
  672. "abcdef",
  673. "\xe3\x81\xaa\xe3\x81\xb2",
  674. %Q(\0),
  675. "",
  676. ]
  677. targets.each do |str|
  678. assert_equal(str, XSD::XSDHexBinary.new(str).string)
  679. assert_equal(str.unpack("H*")[0 ].tr('a-f', 'A-F'),
  680. XSD::XSDHexBinary.new(str).data)
  681. o = XSD::XSDHexBinary.new
  682. o.set_encoded(str.unpack("H*")[0 ].tr('a-f', 'A-F'))
  683. assert_equal(str, o.string)
  684. o.set_encoded(str.unpack("H*")[0 ].tr('A-F', 'a-f'))
  685. assert_equal(str, o.string)
  686. end
  687. targets = [
  688. "0FG7",
  689. "0fg7",
  690. ]
  691. targets.each do |d|
  692. assert_raises(XSD::ValueSpaceError, d.to_s) do
  693. o = XSD::XSDHexBinary.new
  694. o.set_encoded(d)
  695. p o.string
  696. end
  697. end
  698. end
  699. def test_XSDBase64Binary
  700. o = XSD::XSDBase64Binary.new
  701. assert_equal(XSD::Namespace, o.type.namespace)
  702. assert_equal(XSD::Base64BinaryLiteral, o.type.name)
  703. assert_equal(nil, o.data)
  704. assert_equal(true, o.is_nil)
  705. targets = [
  706. "abcdef",
  707. "\xe3\x81\xaa\xe3\x81\xb2",
  708. %Q(\0),
  709. "",
  710. ]
  711. targets.each do |str|
  712. assert_equal(str, XSD::XSDBase64Binary.new(str).string)
  713. assert_equal([str ].pack("m").chomp, XSD::XSDBase64Binary.new(str).data)
  714. o = XSD::XSDBase64Binary.new
  715. o.set_encoded([str ].pack("m").chomp)
  716. assert_equal(str, o.string)
  717. end
  718. targets = [
  719. "-",
  720. "*",
  721. ]
  722. targets.each do |d|
  723. assert_raises(XSD::ValueSpaceError, d.to_s) do
  724. o = XSD::XSDBase64Binary.new
  725. o.set_encoded(d)
  726. p o.string
  727. end
  728. end
  729. end
  730. def test_XSDAnyURI
  731. o = XSD::XSDAnyURI.new
  732. assert_equal(XSD::Namespace, o.type.namespace)
  733. assert_equal(XSD::AnyURILiteral, o.type.name)
  734. assert_equal(nil, o.data)
  735. assert_equal(true, o.is_nil)
  736. # Too few tests here I know. Believe uri module. :)
  737. targets = [
  738. "foo",
  739. "http://foo",
  740. "http://foo/bar/baz",
  741. "http://foo/bar#baz",
  742. "http://foo/bar%20%20?a+b",
  743. "HTTP://FOO/BAR%20%20?A+B",
  744. ]
  745. targets.each do |str|
  746. assert_parsed_result(XSD::XSDAnyURI, str)
  747. end
  748. end
  749. def test_XSDQName
  750. o = XSD::XSDQName.new
  751. assert_equal(XSD::Namespace, o.type.namespace)
  752. assert_equal(XSD::QNameLiteral, o.type.name)
  753. assert_equal(nil, o.data)
  754. assert_equal(true, o.is_nil)
  755. # More strict test is needed but current implementation allows all non-':'
  756. # chars like ' ', C0 or C1...
  757. targets = [
  758. "foo",
  759. "foo:bar",
  760. "a:b",
  761. ]
  762. targets.each do |str|
  763. assert_parsed_result(XSD::XSDQName, str)
  764. end
  765. end
  766. ###
  767. ## Derived types
  768. #
  769. def test_XSDInteger
  770. o = XSD::XSDInteger.new
  771. assert_equal(XSD::Namespace, o.type.namespace)
  772. assert_equal(XSD::IntegerLiteral, o.type.name)
  773. assert_equal(nil, o.data)
  774. assert_equal(true, o.is_nil)
  775. targets = [
  776. 0,
  777. 1000000000,
  778. -9999999999,
  779. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
  780. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
  781. -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
  782. ]
  783. targets.each do |int|
  784. assert_equal(int, XSD::XSDInteger.new(int).data)
  785. end
  786. targets = [
  787. "0",
  788. "1000000000",
  789. "-9999999999",
  790. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  791. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  792. "-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
  793. ]
  794. targets.each do |str|
  795. assert_equal(str, XSD::XSDInteger.new(str).to_s)
  796. end
  797. targets = [
  798. ["-0", "0"],
  799. ["+0", "0"],
  800. ["000123", "123"],
  801. ["-000123", "-123"],
  802. [
  803. "+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  804. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  805. ],
  806. ]
  807. targets.each do |data, expected|
  808. assert_equal(expected, XSD::XSDInteger.new(data).to_s)
  809. end
  810. targets = [
  811. "0.0",
  812. "-5.2",
  813. "0.000000000000a",
  814. "+-5",
  815. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
  816. ]
  817. targets.each do |d|
  818. assert_raises(XSD::ValueSpaceError) do
  819. XSD::XSDInteger.new(d)
  820. end
  821. end
  822. end
  823. def test_XSDNonPositiveInteger
  824. o = XSD::XSDNonPositiveInteger.new
  825. assert_equal(XSD::Namespace, o.type.namespace)
  826. assert_equal(XSD::NonPositiveIntegerLiteral, o.type.name)
  827. assert_equal(nil, o.data)
  828. assert_equal(true, o.is_nil)
  829. targets = [
  830. 0,
  831. -9999999999,
  832. -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
  833. ]
  834. targets.each do |int|
  835. assert_equal(int, XSD::XSDNonPositiveInteger.new(int).data)
  836. end
  837. targets = [
  838. "0",
  839. "-9999999999",
  840. "-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
  841. ]
  842. targets.each do |str|
  843. assert_equal(str, XSD::XSDNonPositiveInteger.new(str).to_s)
  844. end
  845. targets = [
  846. ["-0", "0"],
  847. ["-000123", "-123"],
  848. ]
  849. targets.each do |data, expected|
  850. assert_equal(expected, XSD::XSDNonPositiveInteger.new(data).to_s)
  851. end
  852. targets = [
  853. "0.0",
  854. "-5.2",
  855. "0.000000000000a",
  856. "+-5",
  857. "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
  858. ]
  859. targets.each do |d|
  860. assert_raises(XSD::ValueSpaceError) do
  861. XSD::XSDNonPositiveInteger.new(d)
  862. end
  863. end
  864. end
  865. def test_XSDNegativeInteger
  866. o = XSD::XSDNegativeInteger.new
  867. assert_equal(XSD::Namespace, o.type.namespace)
  868. assert_equal(XSD::NegativeIntegerLiteral, o.type.name)
  869. assert_equal(nil, o.data)
  870. assert_equal(true, o.is_nil)
  871. targets = [
  872. -1,
  873. -9999999999,
  874. -1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,
  875. ]
  876. targets.each do |int|
  877. assert_equal(int, XSD::XSDNegativeInteger.new(int).data)
  878. end
  879. targets = [
  880. "-1",
  881. "-9999999999",
  882. "-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
  883. ]
  884. targets.each do |str|
  885. assert_equal(str, XSD::XSDNegativeInteger.new(str).to_s)
  886. end
  887. targets = [
  888. ["-000123", "-123"],
  889. ]
  890. targets.each do |data, expected|
  891. assert_equal(expected, XSD::XSDNegativeInteger.new(data).to_s)
  892. end
  893. targets = [
  894. "-0.0",
  895. "-5.2",
  896. "-0.000000000000a",
  897. "+-5",
  898. "-12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
  899. ]
  900. targets.each do |d|
  901. assert_raises(XSD::ValueSpaceError) do
  902. XSD::XSDNegativeInteger.new(d)
  903. end
  904. end
  905. end
  906. def test_XSDLong
  907. o = XSD::XSDLong.new
  908. assert_equal(XSD::Namespace, o.type.namespace)
  909. assert_equal(XSD::LongLiteral, o.type.name)
  910. assert_equal(nil, o.data)
  911. assert_equal(true, o.is_nil)
  912. targets = [
  913. 0,
  914. 123,
  915. -123,
  916. 9223372036854775807,
  917. -9223372036854775808,
  918. ]
  919. targets.each do |lng|
  920. assert_equal(lng, XSD::XSDLong.new(lng).data)
  921. end
  922. targets = [
  923. "0",
  924. "123",
  925. "-123",
  926. "9223372036854775807",
  927. "-9223372036854775808",
  928. ]
  929. targets.each do |str|
  930. assert_equal(str, XSD::XSDLong.new(str).to_s)
  931. end
  932. targets = [
  933. ["-0", "0"],
  934. ["+0", "0"],
  935. ["000123", "123"],
  936. ["-000123", "-123"],
  937. ]
  938. targets.each do |data, expected|
  939. assert_equal(expected, XSD::XSDLong.new(data).to_s)
  940. end
  941. targets = [
  942. 9223372036854775808,
  943. -9223372036854775809,
  944. "0.0",
  945. "-5.2",
  946. "0.000000000000a",
  947. "+-5",
  948. ]
  949. targets.each do |d|
  950. assert_raises(XSD::ValueSpaceError) do
  951. XSD::XSDLong.new(d)
  952. end
  953. end
  954. end
  955. def test_XSDInt
  956. o = XSD::XSDInt.new
  957. assert_equal(XSD::Namespace, o.type.namespace)
  958. assert_equal(XSD::IntLiteral, o.type.name)
  959. assert_equal(nil, o.data)
  960. assert_equal(true, o.is_nil)
  961. targets = [
  962. 0,
  963. 123,
  964. -123,
  965. 2147483647,
  966. -2147483648,
  967. ]
  968. targets.each do |lng|
  969. assert_equal(lng, XSD::XSDInt.new(lng).data)
  970. end
  971. targets = [
  972. "0",
  973. "123",
  974. "-123",
  975. "2147483647",
  976. "-2147483648",
  977. ]
  978. targets.each do |str|
  979. assert_equal(str, XSD::XSDInt.new(str).to_s)
  980. end
  981. targets = [
  982. ["-0", "0"],
  983. ["+0", "0"],
  984. ["000123", "123"],
  985. ["-000123", "-123"],
  986. ]
  987. targets.each do |data, expected|
  988. assert_equal(expected, XSD::XSDInt.new(data).to_s)
  989. end
  990. targets = [
  991. 2147483648,
  992. -2147483649,
  993. "0.0",
  994. "-5.2",
  995. "0.000000000000a",
  996. "+-5",
  997. ]
  998. targets.each do |d|
  999. assert_raises(XSD::ValueSpaceError) do
  1000. XSD::XSDInt.new(d)
  1001. end
  1002. end
  1003. end
  1004. def test_XSDShort
  1005. o = XSD::XSDShort.new
  1006. assert_equal(XSD::Namespace, o.type.namespace)
  1007. assert_equal(XSD::ShortLiteral, o.type.name)
  1008. assert_equal(nil, o.data)
  1009. assert_equal(true, o.is_nil)
  1010. targets = [
  1011. 0,
  1012. 123,
  1013. -123,
  1014. 32767,
  1015. -32768,
  1016. ]
  1017. targets.each do |lng|
  1018. assert_equal(lng, XSD::XSDShort.new(lng).data)
  1019. end
  1020. targets = [
  1021. "0",
  1022. "123",
  1023. "-123",
  1024. "32767",
  1025. "-32768",
  1026. ]
  1027. targets.each do |str|
  1028. assert_equal(str, XSD::XSDShort.new(str).to_s)
  1029. end
  1030. targets = [
  1031. ["-0", "0"],
  1032. ["+0", "0"],
  1033. ["000123", "123"],
  1034. ["-000123", "-123"],
  1035. ]
  1036. targets.each do |data, expected|
  1037. assert_equal(expected, XSD::XSDShort.new(data).to_s)
  1038. end
  1039. targets = [
  1040. 32768,
  1041. -32769,
  1042. "0.0",
  1043. "-5.2",
  1044. "0.000000000000a",
  1045. "+-5",
  1046. ]
  1047. targets.each do |d|
  1048. assert_raises(XSD::ValueSpaceError) do
  1049. XSD::XSDShort.new(d)
  1050. end
  1051. end
  1052. end
  1053. def test_XSDByte
  1054. o = XSD::XSDByte.new
  1055. assert_equal(XSD::Namespace, o.type.namespace)
  1056. assert_equal(XSD::ByteLiteral, o.type.name)
  1057. assert_equal(nil, o.data)
  1058. assert_equal(true, o.is_nil)
  1059. targets = [
  1060. 0,
  1061. 123,
  1062. -123,
  1063. 127,
  1064. -128,
  1065. ]
  1066. targets.each do |lng|
  1067. assert_equal(lng, XSD::XSDByte.new(lng).data)
  1068. end
  1069. targets = [
  1070. "0",
  1071. "123",
  1072. "-123",
  1073. "127",
  1074. "-128",
  1075. ]
  1076. targets.each do |str|
  1077. assert_equal(str, XSD::XSDByte.new(str).to_s)
  1078. end
  1079. targets = [
  1080. ["-0", "0"],
  1081. ["+0", "0"],
  1082. ["000123", "123"],
  1083. ["-000123", "-123"],
  1084. ]
  1085. targets.each do |data, expected|
  1086. assert_equal(expected, XSD::XSDByte.new(data).to_s)
  1087. end
  1088. targets = [
  1089. 128,
  1090. -129,
  1091. "0.0",
  1092. "-5.2",
  1093. "0.000000000000a",
  1094. "+-5",
  1095. ]
  1096. targets.each do |d|
  1097. assert_raises(XSD::ValueSpaceError) do
  1098. XSD::XSDByte.new(d)
  1099. end
  1100. end
  1101. end
  1102. def test_XSDNonNegativeInteger
  1103. o = XSD::XSDNonNegativeInteger.new
  1104. assert_equal(XSD::Namespace, o.type.namespace)
  1105. assert_equal(XSD::NonNegativeIntegerLiteral, o.type.name)
  1106. assert_equal(nil, o.data)
  1107. assert_equal(true, o.is_nil)
  1108. targets = [
  1109. 0,
  1110. 1000000000,
  1111. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
  1112. ]
  1113. targets.each do |int|
  1114. assert_equal(int, XSD::XSDNonNegativeInteger.new(int).data)
  1115. end
  1116. targets = [
  1117. "0",
  1118. "1000000000",
  1119. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  1120. ]
  1121. targets.each do |str|
  1122. assert_equal(str, XSD::XSDNonNegativeInteger.new(str).to_s)
  1123. end
  1124. targets = [
  1125. ["-0", "0"],
  1126. ["+0", "0"],
  1127. ["000123", "123"],
  1128. [
  1129. "+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  1130. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  1131. ],
  1132. ]
  1133. targets.each do |data, expected|
  1134. assert_equal(expected, XSD::XSDNonNegativeInteger.new(data).to_s)
  1135. end
  1136. targets = [
  1137. "0.0",
  1138. "0.000000000000a",
  1139. "+-5",
  1140. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
  1141. ]
  1142. targets.each do |d|
  1143. assert_raises(XSD::ValueSpaceError) do
  1144. XSD::XSDNonNegativeInteger.new(d)
  1145. end
  1146. end
  1147. end
  1148. def test_XSDUnsignedLong
  1149. o = XSD::XSDUnsignedLong.new
  1150. assert_equal(XSD::Namespace, o.type.namespace)
  1151. assert_equal(XSD::UnsignedLongLiteral, o.type.name)
  1152. assert_equal(nil, o.data)
  1153. assert_equal(true, o.is_nil)
  1154. targets = [
  1155. 0,
  1156. 1000000000,
  1157. 18446744073709551615,
  1158. ]
  1159. targets.each do |int|
  1160. assert_equal(int, XSD::XSDUnsignedLong.new(int).data)
  1161. end
  1162. targets = [
  1163. "0",
  1164. "1000000000",
  1165. "18446744073709551615",
  1166. ]
  1167. targets.each do |str|
  1168. assert_equal(str, XSD::XSDUnsignedLong.new(str).to_s)
  1169. end
  1170. targets = [
  1171. ["-0", "0"],
  1172. ["+0", "0"],
  1173. ["000123", "123"],
  1174. ["+18446744073709551615", "18446744073709551615"],
  1175. ]
  1176. targets.each do |data, expected|
  1177. assert_equal(expected, XSD::XSDUnsignedLong.new(data).to_s)
  1178. end
  1179. targets = [
  1180. "0.0",
  1181. "0.000000000000a",
  1182. "+-5",
  1183. "18446744073709551615."
  1184. ]
  1185. targets.each do |d|
  1186. assert_raises(XSD::ValueSpaceError) do
  1187. XSD::XSDUnsignedLong.new(d)
  1188. end
  1189. end
  1190. end
  1191. def test_XSDUnsignedInt
  1192. o = XSD::XSDUnsignedInt.new
  1193. assert_equal(XSD::Namespace, o.type.namespace)
  1194. assert_equal(XSD::UnsignedIntLiteral, o.type.name)
  1195. assert_equal(nil, o.data)
  1196. assert_equal(true, o.is_nil)
  1197. targets = [
  1198. 0,
  1199. 1000000000,
  1200. 4294967295,
  1201. ]
  1202. targets.each do |int|
  1203. assert_equal(int, XSD::XSDUnsignedInt.new(int).data)
  1204. end
  1205. targets = [
  1206. "0",
  1207. "1000000000",
  1208. "4294967295",
  1209. ]
  1210. targets.each do |str|
  1211. assert_equal(str, XSD::XSDUnsignedInt.new(str).to_s)
  1212. end
  1213. targets = [
  1214. ["-0", "0"],
  1215. ["+0", "0"],
  1216. ["000123", "123"],
  1217. ["+4294967295", "4294967295"],
  1218. ]
  1219. targets.each do |data, expected|
  1220. assert_equal(expected, XSD::XSDUnsignedInt.new(data).to_s)
  1221. end
  1222. targets = [
  1223. "0.0",
  1224. "0.000000000000a",
  1225. "+-5",
  1226. "4294967295."
  1227. ]
  1228. targets.each do |d|
  1229. assert_raises(XSD::ValueSpaceError) do
  1230. XSD::XSDUnsignedInt.new(d)
  1231. end
  1232. end
  1233. end
  1234. def test_XSDUnsignedShort
  1235. o = XSD::XSDUnsignedShort.new
  1236. assert_equal(XSD::Namespace, o.type.namespace)
  1237. assert_equal(XSD::UnsignedShortLiteral, o.type.name)
  1238. assert_equal(nil, o.data)
  1239. assert_equal(true, o.is_nil)
  1240. targets = [
  1241. 0,
  1242. 10000,
  1243. 65535,
  1244. ]
  1245. targets.each do |int|
  1246. assert_equal(int, XSD::XSDUnsignedShort.new(int).data)
  1247. end
  1248. targets = [
  1249. "0",
  1250. "1000",
  1251. "65535",
  1252. ]
  1253. targets.each do |str|
  1254. assert_equal(str, XSD::XSDUnsignedShort.new(str).to_s)
  1255. end
  1256. targets = [
  1257. ["-0", "0"],
  1258. ["+0", "0"],
  1259. ["000123", "123"],
  1260. ["+65535", "65535"],
  1261. ]
  1262. targets.each do |data, expected|
  1263. assert_equal(expected, XSD::XSDUnsignedShort.new(data).to_s)
  1264. end
  1265. targets = [
  1266. "0.0",
  1267. "0.000000000000a",
  1268. "+-5",
  1269. "65535."
  1270. ]
  1271. targets.each do |d|
  1272. assert_raises(XSD::ValueSpaceError) do
  1273. XSD::XSDUnsignedShort.new(d)
  1274. end
  1275. end
  1276. end
  1277. def test_XSDUnsignedByte
  1278. o = XSD::XSDUnsignedByte.new
  1279. assert_equal(XSD::Namespace, o.type.namespace)
  1280. assert_equal(XSD::UnsignedByteLiteral, o.type.name)
  1281. assert_equal(nil, o.data)
  1282. assert_equal(true, o.is_nil)
  1283. targets = [
  1284. 0,
  1285. 10,
  1286. 255,
  1287. ]
  1288. targets.each do |int|
  1289. assert_equal(int, XSD::XSDUnsignedByte.new(int).data)
  1290. end
  1291. targets = [
  1292. "0",
  1293. "10",
  1294. "255",
  1295. ]
  1296. targets.each do |str|
  1297. assert_equal(str, XSD::XSDUnsignedByte.new(str).to_s)
  1298. end
  1299. targets = [
  1300. ["-0", "0"],
  1301. ["+0", "0"],
  1302. ["000123", "123"],
  1303. ["+255", "255"],
  1304. ]
  1305. targets.each do |data, expected|
  1306. assert_equal(expected, XSD::XSDUnsignedByte.new(data).to_s)
  1307. end
  1308. targets = [
  1309. "0.0",
  1310. "0.000000000000a",
  1311. "+-5",
  1312. "255."
  1313. ]
  1314. targets.each do |d|
  1315. assert_raises(XSD::ValueSpaceError) do
  1316. XSD::XSDUnsignedByte.new(d)
  1317. end
  1318. end
  1319. end
  1320. def test_XSDPositiveInteger
  1321. o = XSD::XSDPositiveInteger.new
  1322. assert_equal(XSD::Namespace, o.type.namespace)
  1323. assert_equal(XSD::PositiveIntegerLiteral, o.type.name)
  1324. assert_equal(nil, o.data)
  1325. assert_equal(true, o.is_nil)
  1326. targets = [
  1327. 1,
  1328. 1000000000,
  1329. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
  1330. ]
  1331. targets.each do |int|
  1332. assert_equal(int, XSD::XSDPositiveInteger.new(int).data)
  1333. end
  1334. targets = [
  1335. "1",
  1336. "1000000000",
  1337. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  1338. ]
  1339. targets.each do |str|
  1340. assert_equal(str, XSD::XSDPositiveInteger.new(str).to_s)
  1341. end
  1342. targets = [
  1343. ["+1", "1"],
  1344. ["000123", "123"],
  1345. [
  1346. "+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  1347. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  1348. ],
  1349. ]
  1350. targets.each do |data, expected|
  1351. assert_equal(expected, XSD::XSDPositiveInteger.new(data).to_s)
  1352. end
  1353. targets = [
  1354. "1.0",
  1355. "1.000000000000a",
  1356. "+-5",
  1357. "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890."
  1358. ]
  1359. targets.each do |d|
  1360. assert_raises(XSD::ValueSpaceError) do
  1361. XSD::XSDPositiveInteger.new(d)
  1362. end
  1363. end
  1364. end
  1365. end
  1366. end