A fork of Crisp for HARP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
1.7 KiB

  1. ;; Testing read of nil/true/false
  2. nil
  3. ;=>nil
  4. true
  5. ;=>true
  6. false
  7. ;=>false
  8. ;; Testing read of numbers
  9. 1
  10. ;=>1
  11. 7
  12. ;=>7
  13. 7
  14. ;=>7
  15. ;; Testing read of symbols
  16. +
  17. ;=>+
  18. abc
  19. ;=>abc
  20. abc
  21. ;=>abc
  22. abc5
  23. ;=>abc5
  24. abc-def
  25. ;=>abc-def
  26. ;; Testing read of strings
  27. "abc"
  28. ;=>"abc"
  29. "abc"
  30. ;=>"abc"
  31. "abc (with parens)"
  32. ;=>"abc (with parens)"
  33. "abc\"def"
  34. ;=>"abc\"def"
  35. ;;;"abc\ndef"
  36. ;;;;=>"abc\ndef"
  37. ""
  38. ;=>""
  39. ;; Testing read of lists
  40. (+ 1 2)
  41. ;=>(+ 1 2)
  42. ((3 4))
  43. ;=>((3 4))
  44. (+ 1 (+ 2 3))
  45. ;=>(+ 1 (+ 2 3))
  46. ( + 1 (+ 2 3 ) )
  47. ;=>(+ 1 (+ 2 3))
  48. (* 1 2)
  49. ;=>(* 1 2)
  50. (** 1 2)
  51. ;=>(** 1 2)
  52. ;; Test commas as whitespace
  53. (1 2, 3,,,,),,
  54. ;=>(1 2 3)
  55. ;; Testing read of quoting
  56. '1
  57. ;=>(quote 1)
  58. '(1 2 3)
  59. ;=>(quote (1 2 3))
  60. `1
  61. ;=>(quasiquote 1)
  62. `(1 2 3)
  63. ;=>(quasiquote (1 2 3))
  64. ~1
  65. ;=>(unquote 1)
  66. ~(1 2 3)
  67. ;=>(unquote (1 2 3))
  68. ~@(1 2 3)
  69. ;=>(splice-unquote (1 2 3))
  70. ;;
  71. ;; Testing reader errors
  72. ;;; TODO: fix these so they fail correctly
  73. (1 2
  74. ; expected ')', got EOF
  75. [1 2
  76. ; expected ']', got EOF
  77. "abc
  78. ; expected '"', got EOF
  79. ;;
  80. ;; -------- Optional Functionality --------
  81. ;; Testing keywords
  82. :kw
  83. ;=>:kw
  84. (:kw1 :kw2 :kw3)
  85. ;=>(:kw1 :kw2 :kw3)
  86. ;; Testing read of vectors
  87. [+ 1 2]
  88. ;=>[+ 1 2]
  89. [[3 4]]
  90. ;=>[[3 4]]
  91. [+ 1 [+ 2 3]]
  92. ;=>[+ 1 [+ 2 3]]
  93. [ + 1 [+ 2 3 ] ]
  94. ;=>[+ 1 [+ 2 3]]
  95. ;; Testing read of hash maps
  96. {"abc" 1}
  97. ;=>{"abc" 1}
  98. {"a" {"b" 2}}
  99. ;=>{"a" {"b" 2}}
  100. {"a" {"b" {"c" 3}}}
  101. ;=>{"a" {"b" {"c" 3}}}
  102. { "a" {"b" { "cde" 3 } }}
  103. ;=>{"a" {"b" {"cde" 3}}}
  104. { :a {:b { :cde 3 } }}
  105. ;=>{:a {:b {:cde 3}}}
  106. ;; Testing read of comments
  107. ;; whole line comment (not an exception)
  108. 1 ; comment after expression
  109. ;=>1
  110. 1; comment after expression
  111. ;=>1
  112. ;; Testing read of ^/metadata
  113. ^{"a" 1} [1 2 3]
  114. ;=>(with-meta [1 2 3] {"a" 1})
  115. ;; Testing read of @/deref
  116. @a
  117. ;=>(deref a)