tmitems.nim 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. discard """
  2. output: '''@[11, 12, 13]
  3. @[11, 12, 13]
  4. @[1, 3, 5]
  5. @[1, 3, 5]
  6. gppcbs
  7. gppcbs
  8. fpqeew
  9. fpqeew
  10. [11, 12, 13]
  11. [11, 12, 13]
  12. [11, 12, 13]
  13. [11, 12, 13]
  14. 11 12 13
  15. [11,12,13]
  16. <Students>
  17. <Student Name="Aprilfoo" />
  18. <Student Name="bar" />
  19. </Students>
  20. <chapter>
  21. <title>This is a Docbook title</title>
  22. <para>
  23. This is a Docbook paragraph containing <emphasis>emphasized</emphasis>,
  24. <literal>literal</literal> and <replaceable>replaceable</replaceable>
  25. text. Sometimes scrunched together like this:
  26. <literal>literal</literal><replaceable>replaceable</replaceable>
  27. and sometimes not:
  28. <literal>literal</literal> <replaceable>replaceable</replaceable>
  29. </para>
  30. </chapter>'''
  31. """
  32. block:
  33. var xs = @[1,2,3]
  34. for x in xs.mitems:
  35. x += 10
  36. echo xs
  37. block:
  38. var xs = [1,2,3]
  39. for x in xs.mitems:
  40. x += 10
  41. echo(@xs)
  42. block:
  43. var xs = @[1,2,3]
  44. for i, x in xs.mpairs:
  45. x += i
  46. echo xs
  47. block:
  48. var xs = [1,2,3]
  49. for i, x in xs.mpairs:
  50. x += i
  51. echo(@xs)
  52. block:
  53. var x = "foobar"
  54. for c in x.mitems:
  55. inc c
  56. echo x
  57. block:
  58. var x = "foobar"
  59. var y = cast[cstring](addr x[0])
  60. for c in y.mitems:
  61. inc c
  62. echo x
  63. block:
  64. var x = "foobar"
  65. for i, c in x.mpairs:
  66. inc c, i
  67. echo x
  68. block:
  69. var x = "foobar"
  70. var y = cast[cstring](addr x[0])
  71. for i, c in y.mpairs:
  72. inc c, i
  73. echo x
  74. import lists
  75. block:
  76. var sl = initSinglyLinkedList[int]()
  77. sl.prepend(3)
  78. sl.prepend(2)
  79. sl.prepend(1)
  80. for x in sl.mitems:
  81. x += 10
  82. echo sl
  83. block:
  84. var sl = initDoublyLinkedList[int]()
  85. sl.append(1)
  86. sl.append(2)
  87. sl.append(3)
  88. for x in sl.mitems:
  89. x += 10
  90. echo sl
  91. block:
  92. var sl = initDoublyLinkedRing[int]()
  93. sl.append(1)
  94. sl.append(2)
  95. sl.append(3)
  96. for x in sl.mitems:
  97. x += 10
  98. echo sl
  99. import deques
  100. block:
  101. var q = initDeque[int]()
  102. q.addLast(1)
  103. q.addLast(2)
  104. q.addLast(3)
  105. for x in q.mitems:
  106. x += 10
  107. echo q
  108. import json
  109. block:
  110. var j = parseJson """{"key1": 1, "key2": 2, "key3": 3}"""
  111. for key,val in j.pairs:
  112. val.num += 10
  113. echo j["key1"], " ", j["key2"], " ", j["key3"]
  114. block:
  115. var j = parseJson """[1, 2, 3]"""
  116. for x in j.mitems:
  117. x.num += 10
  118. echo j
  119. import xmltree, xmlparser, parsexml, streams, strtabs
  120. block:
  121. var d = parseXml(newStringStream """<Students>
  122. <Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
  123. <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
  124. </Students>""")
  125. for x in d.mitems:
  126. x = <>Student(Name=x.attrs["Name"] & "foo")
  127. d[1].attrs["Name"] = "bar"
  128. echo d
  129. block:
  130. var d = parseXml(newStringStream """<chapter>
  131. <title>This is a Docbook title</title>
  132. <para>
  133. This is a Docbook paragraph containing <emphasis>emphasized</emphasis>,
  134. <literal>literal</literal> and <replaceable>replaceable</replaceable>
  135. text. Sometimes scrunched together like this:
  136. <literal>literal</literal><replaceable>replaceable</replaceable>
  137. and sometimes not:
  138. <literal>literal</literal> <replaceable>replaceable</replaceable>
  139. </para>
  140. </chapter>""",{reportComments, reportWhitespace})
  141. echo d