tmitems.nim 3.1 KB

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