PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/test/scanner/test_properties.rb

https://github.com/coatl/regexp_parser
Ruby | 315 lines | 218 code | 97 blank | 0 comment | 0 complexity | 7050c7e7d4ddc5e7699141057615f75a MD5 | raw file
  1. require File.expand_path("../../helpers", __FILE__)
  2. class ScannerProperties < Test::Unit::TestCase
  3. tests = {
  4. 'Alnum' => :alnum,
  5. 'Alpha' => :alpha,
  6. 'Any' => :any,
  7. 'Ascii' => :ascii,
  8. 'Blank' => :blank,
  9. 'Cntrl' => :cntrl,
  10. 'Digit' => :digit,
  11. 'Graph' => :graph,
  12. 'Lower' => :lower,
  13. 'Newline' => :newline,
  14. 'Print' => :print,
  15. 'Punct' => :punct,
  16. 'Space' => :space,
  17. 'Upper' => :upper,
  18. 'Word' => :word,
  19. 'Xdigit' => :xdigit,
  20. 'L' => :letter_any,
  21. 'Letter' => :letter_any,
  22. 'Lu' => :letter_uppercase,
  23. 'Uppercase_Letter' => :letter_uppercase,
  24. 'Ll' => :letter_lowercase,
  25. 'Lowercase_Letter' => :letter_lowercase,
  26. 'Lt' => :letter_titlecase,
  27. 'Titlecase_Letter' => :letter_titlecase,
  28. 'Lm' => :letter_modifier,
  29. 'Modifier_Letter' => :letter_modifier,
  30. 'Lo' => :letter_other,
  31. 'Other_Letter' => :letter_other,
  32. 'M' => :mark_any,
  33. 'Mark' => :mark_any,
  34. 'Mn' => :mark_nonspacing,
  35. 'Nonspacing_Mark' => :mark_nonspacing,
  36. 'Mc' => :mark_spacing,
  37. 'Spacing_Mark' => :mark_spacing,
  38. 'Me' => :mark_enclosing,
  39. 'Enclosing_Mark' => :mark_enclosing,
  40. 'N' => :number_any,
  41. 'Number' => :number_any,
  42. 'Nd' => :number_decimal,
  43. 'Decimal_Number' => :number_decimal,
  44. 'Nl' => :number_letter,
  45. 'Letter_Number' => :number_letter,
  46. 'No' => :number_other,
  47. 'Other_Number' => :number_other,
  48. 'P' => :punct_any,
  49. 'Punctuation' => :punct_any,
  50. 'Pc' => :punct_connector,
  51. 'Connector_Punctuation' => :punct_connector,
  52. 'Pd' => :punct_dash,
  53. 'Dash_Punctuation' => :punct_dash,
  54. 'Ps' => :punct_open,
  55. 'Open_Punctuation' => :punct_open,
  56. 'Pe' => :punct_close,
  57. 'Close_Punctuation' => :punct_close,
  58. 'Pi' => :punct_initial,
  59. 'Initial_Punctuation' => :punct_initial,
  60. 'Pf' => :punct_final,
  61. 'Final_Punctuation' => :punct_final,
  62. 'Po' => :punct_other,
  63. 'Other_Punctuation' => :punct_other,
  64. 'S' => :symbol_any,
  65. 'Symbol' => :symbol_any,
  66. 'Sm' => :symbol_math,
  67. 'Math_Symbol' => :symbol_math,
  68. 'Sc' => :symbol_currency,
  69. 'Currency_Symbol' => :symbol_currency,
  70. 'Sk' => :symbol_modifier,
  71. 'Modifier_Symbol' => :symbol_modifier,
  72. 'So' => :symbol_other,
  73. 'Other_Symbol' => :symbol_other,
  74. 'Z' => :separator_any,
  75. 'Separator' => :separator_any,
  76. 'Zs' => :separator_space,
  77. 'Space_Separator' => :separator_space,
  78. 'Zl' => :separator_line,
  79. 'Line_Separator' => :separator_line,
  80. 'Zp' => :separator_para,
  81. 'Paragraph_Separator' => :separator_para,
  82. 'C' => :other,
  83. 'Other' => :other,
  84. 'Cc' => :control,
  85. 'Control' => :control,
  86. 'Cf' => :format,
  87. 'Format' => :format,
  88. 'Cs' => :surrogate,
  89. 'Surrogate' => :surrogate,
  90. 'Co' => :private_use,
  91. 'Private_Use' => :private_use,
  92. 'Cn' => :unassigned,
  93. 'Unassigned' => :unassigned,
  94. 'Age=1.1' => :age_1_1,
  95. 'Age=2.0' => :age_2_0,
  96. 'Age=2.1' => :age_2_1,
  97. 'Age=3.0' => :age_3_0,
  98. 'Age=3.1' => :age_3_1,
  99. 'Age=3.2' => :age_3_2,
  100. 'Age=4.0' => :age_4_0,
  101. 'Age=4.1' => :age_4_1,
  102. 'Age=5.0' => :age_5_0,
  103. 'Age=5.1' => :age_5_1,
  104. 'Age=5.2' => :age_5_2,
  105. 'Age=6.0' => :age_6_0,
  106. 'ahex' => :ascii_hex,
  107. 'ASCII_Hex_Digit' => :ascii_hex,
  108. 'Alphabetic' => :alphabetic,
  109. 'Cased' => :cased,
  110. 'cwcf' => :changes_when_casefolded,
  111. 'Changes_When_Casefolded' => :changes_when_casefolded,
  112. 'cwcm' => :changes_when_casemapped,
  113. 'Changes_When_Casemapped' => :changes_when_casemapped,
  114. 'cwl' => :changes_when_lowercased,
  115. 'Changes_When_Lowercased' => :changes_when_lowercased,
  116. 'cwt' => :changes_when_titlecased,
  117. 'Changes_When_Titlecased' => :changes_when_titlecased,
  118. 'cwu' => :changes_when_uppercased,
  119. 'Changes_When_Uppercased' => :changes_when_uppercased,
  120. 'ci' => :case_ignorable,
  121. 'Case_Ignorable' => :case_ignorable,
  122. 'bidic' => :bidi_control,
  123. 'Bidi_Control' => :bidi_control,
  124. 'Dash' => :dash,
  125. 'dep' => :deprecated,
  126. 'Deprecated' => :deprecated,
  127. 'di' => :default_ignorable_cp,
  128. 'Default_Ignorable_Code_Point' => :default_ignorable_cp,
  129. 'dia' => :diacritic,
  130. 'Diacritic' => :diacritic,
  131. 'ext' => :extender,
  132. 'Extender' => :extender,
  133. 'grbase' => :grapheme_base,
  134. 'Grapheme_Base' => :grapheme_base,
  135. 'grext' => :grapheme_extend,
  136. 'Grapheme_Extend' => :grapheme_extend,
  137. 'grlink' => :grapheme_link,
  138. 'Grapheme_Link' => :grapheme_link,
  139. 'hex' => :hex_digit,
  140. 'Hex_Digit' => :hex_digit,
  141. 'Hyphen' => :hyphen,
  142. 'idc' => :id_continue,
  143. 'ID_Continue' => :id_continue,
  144. 'ideo' => :ideographic,
  145. 'Ideographic' => :ideographic,
  146. 'ids' => :id_start,
  147. 'ID_Start' => :id_start,
  148. 'idsb' => :ids_binary_op,
  149. 'IDS_Binary_Operator' => :ids_binary_op,
  150. 'idst' => :ids_trinary_op,
  151. 'IDS_Trinary_Operator' => :ids_trinary_op,
  152. 'joinc' => :join_control,
  153. 'Join_Control' => :join_control,
  154. 'loe' => :logical_order_exception,
  155. 'Logical_Order_Exception' => :logical_order_exception,
  156. 'Lowercase' => :lowercase,
  157. 'Math' => :math,
  158. 'nchar' => :non_character_cp,
  159. 'Noncharacter_Code_Point' => :non_character_cp,
  160. 'oalpha' => :other_alphabetic,
  161. 'Other_Alphabetic' => :other_alphabetic,
  162. 'odi' => :other_default_ignorable_cp,
  163. 'Other_Default_Ignorable_Code_Point' => :other_default_ignorable_cp,
  164. 'ogrext' => :other_grapheme_extended,
  165. 'Other_Grapheme_Extend' => :other_grapheme_extended,
  166. 'oidc' => :other_id_continue,
  167. 'Other_ID_Continue' => :other_id_continue,
  168. 'oids' => :other_id_start,
  169. 'Other_ID_Start' => :other_id_start,
  170. 'olower' => :other_lowercase,
  171. 'Other_Lowercase' => :other_lowercase,
  172. 'omath' => :other_math,
  173. 'Other_Math' => :other_math,
  174. 'oupper' => :other_uppercase,
  175. 'Other_Uppercase' => :other_uppercase,
  176. 'patsyn' => :pattern_syntax,
  177. 'Pattern_Syntax' => :pattern_syntax,
  178. 'patws' => :pattern_whitespace,
  179. 'Pattern_Whitespace' => :pattern_whitespace,
  180. 'qmark' => :quotation_mark,
  181. 'quotationmark' => :quotation_mark,
  182. 'radical' => :radical,
  183. 'sd' => :soft_dotted,
  184. 'Soft_Dotted' => :soft_dotted,
  185. 'sterm' => :sentence_terminal,
  186. 'term' => :terminal_punctuation,
  187. 'Terminal_Punctuation' => :terminal_punctuation,
  188. 'uideo' => :unified_ideograph,
  189. 'Unified_Ideograph' => :unified_ideograph,
  190. 'Uppercase' => :uppercase,
  191. 'vs' => :variation_selector,
  192. 'Variation_Selector' => :variation_selector,
  193. 'wspace' => :whitespace,
  194. 'whitespace' => :whitespace,
  195. 'xids' => :xid_start,
  196. 'XID_Start' => :xid_start,
  197. 'xidc' => :xid_continue,
  198. 'XID_Continue' => :xid_continue,
  199. }
  200. count = 0
  201. tests.each do |property, test|
  202. define_method "test_scan_property_#{test}_#{count+=1}" do
  203. token = RS.scan("a\\p{#{property}}c")[1]
  204. assert_equal( :property, token[0] )
  205. assert_equal( test, token[1] )
  206. end
  207. define_method "test_scan_nonproperty_#{test}_#{count+=1}" do
  208. token = RS.scan("a\\P{#{property}}c")[1]
  209. assert_equal( :nonproperty, token[0] )
  210. assert_equal( test, token[1] )
  211. end
  212. define_method "test_scan_caret_nonproperty_#{test}_#{count+=1}" do
  213. token = RS.scan("a\\p{^#{property}}c")[1]
  214. assert_equal( :nonproperty, token[0] )
  215. assert_equal( test, token[1] )
  216. end
  217. end
  218. end