PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Bundles/eBundles/Ruby.tmbundle/Test/questionmark_ambiguity1.rb

http://luapack.googlecode.com/
Ruby | 160 lines | 72 code | 33 blank | 55 comment | 0 complexity | 7597c87b07b9cf3c05dad55c7bb0244f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, ISC
  1. # purpose:
  2. # exercise constructs with questionmark
  3. #
  4. # numeric letters ?x
  5. # ternary operator condition ? case1 : case2
  6. #
  7. #
  8. #
  9. def test(v)
  10. puts "#{v.inspect} => #{v.chr}"
  11. end
  12. def z(v)
  13. v
  14. end
  15. # -------------------------------------------
  16. #
  17. # Testarea for numeric letters
  18. #
  19. # -------------------------------------------
  20. # begin of line
  21. test(
  22. ?x)
  23. # normal letters
  24. test( ?a )
  25. test( ?A )
  26. test( ?0 )
  27. # misc symbols
  28. test( ?* )
  29. test( ?**2 )
  30. test( ?: )
  31. test( ?) )
  32. test( ?( )
  33. test( ?' ) # im a comment, not a string
  34. test( ?" ) # im a comment, not a string
  35. test( ?/ ) # im a comment, not a regexp
  36. # symbol '.'
  37. test( ?..succ )
  38. p ?...?..succ # im a .. range
  39. p ?....?..succ # im a ... range
  40. #p ?.....?..succ # invalid
  41. # symbol '#'
  42. test( ?# ); p 'im not a comment'
  43. # space ' '
  44. #test( ? ) # invalid
  45. # tab ' '
  46. #test( ? ) # invalid
  47. # symbol '?'
  48. test( ?? )
  49. test(??)
  50. # symbol '\\'
  51. test( ?\\ )
  52. # escaped as hex
  53. #test( ?\x ) # invalid
  54. test( ?\x1 )
  55. test( ?\x61 )
  56. #test( ?\x612 ) # invalid
  57. test( ?\X ) # valid.. but is not hex
  58. #test( ?\X11 ) # invalid
  59. # escaped as octal
  60. test( ?\0 )
  61. test( ?\07 )
  62. test( ?\017 )
  63. #test( ?\0173 ) # invalid
  64. #test( ?\08 ) # invalid
  65. #test( ?\09 ) # invalid
  66. #test( ?\0a ) # invalid
  67. test( ?\1 )
  68. test( ?\7 )
  69. test( ?\a )
  70. test( ?\f )
  71. # standard escapings
  72. test( ?\n ) # newline
  73. test( ?\b ) # backspace
  74. # escaped misc letters/symbols
  75. test( ?\8 )
  76. test( ?\9 )
  77. test( ?\_ )
  78. # ctrl/meta escaped
  79. test( ?\C-a )
  80. test( ?\C-g )
  81. test( ?\C-x )
  82. test( ?\C-A )
  83. test( ?\C-G )
  84. test( ?\c )
  85. test( ?\m )
  86. #test( ?\c-a ) # invalid
  87. #test( ?\C ) # invalid
  88. #test( ?\M ) # invalid
  89. test( ?\M-a )
  90. test( ?\M-\C-a )
  91. test( ?\C-\C-\M-a )
  92. test( ?\C-\M-a )
  93. test( ?\C-\M-\M-a )
  94. test( ?\C-\M-\C-\M-a )
  95. # misc tests
  96. p 'abc'.include?(?z)
  97. # -------------------------------------------
  98. #
  99. # Testarea for ternary operator
  100. #
  101. # -------------------------------------------
  102. a, b, val = 42, 24, true
  103. p(val ? 0 : 2)
  104. p [
  105. val ? (a) : z(b) ,
  106. val ? 'a' : 'b'
  107. ]
  108. # -------------------------------------------
  109. #
  110. # Testarea for ternary operator and numeric letter
  111. #
  112. # -------------------------------------------
  113. p [
  114. # very ugly
  115. true ???:?? ,
  116. true ???:?: ,
  117. true ??::?: ,
  118. ]
  119. # -------------------------------------------
  120. #
  121. # Testarea for neiter ternary operator nor numeric letter
  122. #
  123. # -------------------------------------------
  124. # not letters.. the questionmark is part of the methodname
  125. p(42.tainted?, 42.frozen?)