tmitems.nim 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. prepareMutation(x)
  60. var y = cast[cstring](addr x[0])
  61. for c in y.mitems:
  62. inc c
  63. echo x
  64. block:
  65. var x = "foobar"
  66. for i, c in x.mpairs:
  67. inc c, i
  68. echo x
  69. block:
  70. var x = "foobar"
  71. prepareMutation(x)
  72. var y = cast[cstring](addr x[0])
  73. for i, c in y.mpairs:
  74. inc c, i
  75. echo x
  76. import lists
  77. block:
  78. var sl = initSinglyLinkedList[int]()
  79. sl.prepend(3)
  80. sl.prepend(2)
  81. sl.prepend(1)
  82. for x in sl.mitems:
  83. x += 10
  84. echo sl
  85. block:
  86. var sl = initDoublyLinkedList[int]()
  87. sl.append(1)
  88. sl.append(2)
  89. sl.append(3)
  90. for x in sl.mitems:
  91. x += 10
  92. echo sl
  93. block:
  94. var sl = initDoublyLinkedRing[int]()
  95. sl.append(1)
  96. sl.append(2)
  97. sl.append(3)
  98. for x in sl.mitems:
  99. x += 10
  100. echo sl
  101. import deques
  102. block:
  103. var q = initDeque[int]()
  104. q.addLast(1)
  105. q.addLast(2)
  106. q.addLast(3)
  107. for x in q.mitems:
  108. x += 10
  109. echo q
  110. import json
  111. block:
  112. var j = parseJson """{"key1": 1, "key2": 2, "key3": 3}"""
  113. for key,val in j.pairs:
  114. val.num += 10
  115. echo j["key1"], " ", j["key2"], " ", j["key3"]
  116. block:
  117. var j = parseJson """[1, 2, 3]"""
  118. for x in j.mitems:
  119. x.num += 10
  120. echo j
  121. import xmltree, xmlparser, parsexml, streams, strtabs
  122. block:
  123. var d = parseXml(newStringStream """<Students>
  124. <Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
  125. <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
  126. </Students>""")
  127. for x in d.mitems:
  128. x = <>Student(Name=x.attrs["Name"] & "foo")
  129. d[1].attrs["Name"] = "bar"
  130. echo d
  131. block:
  132. var d = parseXml(newStringStream """<chapter>
  133. <title>This is a Docbook title</title>
  134. <para>
  135. This is a Docbook paragraph containing <emphasis>emphasized</emphasis>,
  136. <literal>literal</literal> and <replaceable>replaceable</replaceable>
  137. text. Sometimes scrunched together like this:
  138. <literal>literal</literal><replaceable>replaceable</replaceable>
  139. and sometimes not:
  140. <literal>literal</literal> <replaceable>replaceable</replaceable>
  141. </para>
  142. </chapter>""",{reportComments, reportWhitespace})
  143. echo d