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

/src/com/xruby/compiler/parser/RubyLexerTest.java

http://xruby.googlecode.com/
Java | 1573 lines | 1261 code | 221 blank | 91 comment | 4 complexity | 09732faece5899bf65bd04b6c971849b MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. * Copyright 2005-2007 Xue Yong Zhi
  3. * Distributed under the Apache License
  4. */
  5. package com.xruby.compiler.parser;
  6. import java.io.*;
  7. import junit.framework.*;
  8. import antlr.Token;
  9. import antlr.TokenStreamException;
  10. import antlr.CommonToken;
  11. class TestingCommonToken extends CommonToken {
  12. public TestingCommonToken(int t, String txt) {
  13. super(t, txt);
  14. setLine(1);
  15. }
  16. public TestingCommonToken(int t, String txt, int line) {
  17. super(t, txt);
  18. setLine(line);
  19. }
  20. }
  21. public class RubyLexerTest extends TestCase implements RubyTokenTypes {
  22. private void assert_type(String[] program_texts, int expected_type, String[] expected_texts) {
  23. assertEquals("Length mismatch, setup expected_texts properly!", program_texts.length, expected_texts.length);
  24. for (int i = 0; i < program_texts.length; ++i) {
  25. try {
  26. RubyLexer lexer = new RubyLexer(new StringReader(program_texts[i]), false);
  27. Token token = lexer.nextToken();
  28. assertEquals(program_texts[i], expected_type, token.getType());
  29. assertEquals(program_texts[i], expected_texts[i], token.getText());
  30. // should contain only one token
  31. if (Token.EOF_TYPE == token.getType()) {
  32. Token next_token = lexer.nextToken();
  33. assertEquals(program_texts[i] + "contains multiple tokens!", Token.EOF_TYPE, next_token.getType());
  34. }
  35. } catch (TokenStreamException e) {
  36. assertTrue(program_texts[i]+ e.toString(), false);
  37. }
  38. }
  39. }
  40. private void assert_type(String[] program_texts, int expected_type) {
  41. assert_type(program_texts, expected_type, program_texts);
  42. }
  43. private void assert_type(String program_text, int expected_type, String expected_text) {
  44. try {
  45. RubyLexer lexer = new RubyLexer(new StringReader(program_text), false);
  46. Token token = lexer.nextToken();
  47. assertEquals(program_text, expected_type, token.getType());
  48. assertEquals(program_text, expected_text, token.getText());
  49. } catch (TokenStreamException e) {
  50. assertTrue(program_text + e.toString(), false);
  51. }
  52. }
  53. private void assert_type(String program_text, TestingCommonToken[] tokens) {
  54. try {
  55. RubyLexer lexer = new RubyLexer(new StringReader(program_text), false);
  56. for (int i = 0; i < tokens.length; ++i) {
  57. Token token = lexer.nextToken();
  58. assertEquals(i + " " + token.getText() + " has wrong type!", tokens[i].getType(), token.getType());
  59. assertEquals(i + " " + token.getText() + " has wrong text!", tokens[i].getText(), token.getText());
  60. assertEquals(i + " " + token.getText() + " has wrong position!", tokens[i].getLine(), token.getLine());
  61. }
  62. Token token = lexer.nextToken();
  63. assertEquals("should have no token left!", token.getType(), Token.EOF_TYPE);
  64. } catch (TokenStreamException e) {
  65. assertTrue(program_text + e.toString(), false);
  66. }
  67. }
  68. private void assert_type(String program_text, int expected_type) {
  69. assert_type(program_text, expected_type, program_text);
  70. }
  71. public void test_token_stream1() {
  72. String program_text = "puts \"hello\";";
  73. TestingCommonToken[] token_types = {
  74. new TestingCommonToken(FUNCTION, "puts"),
  75. new TestingCommonToken(DOUBLE_QUOTE_STRING, "hello"),
  76. new TestingCommonToken(SEMI, ";"),
  77. };
  78. assert_type(program_text, token_types);
  79. }
  80. public void test_token_stream2() {
  81. String program_text = "0.step";
  82. TestingCommonToken[] token_types = {
  83. new TestingCommonToken(INTEGER, "0"),
  84. new TestingCommonToken(DOT, "."),
  85. new TestingCommonToken(FUNCTION, "step"),
  86. };
  87. assert_type(program_text, token_types);
  88. }
  89. public void test_token_stream3() {
  90. String program_text = "$?/256";
  91. TestingCommonToken[] token_types = {
  92. new TestingCommonToken(GLOBAL_VARIABLE , "$?"),
  93. new TestingCommonToken(DIV, "/"),
  94. new TestingCommonToken(INTEGER, "256"),
  95. };
  96. assert_type(program_text, token_types);
  97. }
  98. public void test_token_stream4() {
  99. String program_text = " def /(item)";
  100. TestingCommonToken[] token_types = {
  101. new TestingCommonToken(LITERAL_def, "def"),
  102. new TestingCommonToken(DIV, "/"),
  103. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  104. new TestingCommonToken(FUNCTION, "item"),
  105. new TestingCommonToken(RPAREN, ")"),
  106. };
  107. assert_type(program_text, token_types);
  108. }
  109. public void test_token_stream5() {
  110. String program_text = "def -@(); end";
  111. TestingCommonToken[] token_types = {
  112. new TestingCommonToken(LITERAL_def, "def"),
  113. new TestingCommonToken(UNARY_PLUS_MINUS_METHOD_NAME, "-@"),
  114. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  115. new TestingCommonToken(RPAREN, ")"),
  116. new TestingCommonToken(SEMI, ";"),
  117. new TestingCommonToken(LITERAL_end, "end"),
  118. };
  119. assert_type(program_text, token_types);
  120. }
  121. /*need parser
  122. public void test_token_stream6() {
  123. String program_text = "puts <<EOS\n" +
  124. "Usage: #{123} [--key keypair_file] name\n" +
  125. " name ... ex. /C=JP/O=RRR/OU=CA/CN=NaHi/emailAddress=nahi@example.org\n" +
  126. "EOS\n";
  127. TestingCommonToken[] token_types = {
  128. new TestingCommonToken(FUNCTION, "puts"),
  129. new TestingCommonToken(HERE_DOC_BEGIN, "EOS"),
  130. new TestingCommonToken(HERE_DOC_BEFORE_EXPRESSION_SUBSTITUTION, "Usage: "),
  131. new TestingCommonToken(LCURLY_BLOCK, "{"),
  132. new TestingCommonToken(INTEGER, "123"),
  133. new TestingCommonToken(RCURLY, "}"),
  134. new TestingCommonToken(HERE_DOC_AFTER_EXPRESSION_SUBSTITUTION, " [--key keypair_file] name\n" +
  135. " name ... ex. /C=JP/O=RRR/OU=CA/CN=NaHi/emailAddress=nahi@example.org\n"),
  136. new TestingCommonToken(LINE_BREAK, "\n", 4),
  137. };
  138. assert_type(program_text, token_types);
  139. }*/
  140. public void test_token_stream7() {
  141. String program_text =
  142. " res.body =<<-_end_of_html_\r\n" +
  143. " <HTML/>\n" +
  144. " _end_of_html_\n";
  145. TestingCommonToken[] token_types = {
  146. new TestingCommonToken(FUNCTION, "res"),
  147. new TestingCommonToken(DOT, "."),
  148. new TestingCommonToken(FUNCTION, "body"),
  149. new TestingCommonToken(ASSIGN, "="),
  150. new TestingCommonToken(HERE_DOC_BEGIN, "-_end_of_html_"),
  151. new TestingCommonToken(HERE_DOC_CONTENT, " <HTML/>\n"),
  152. new TestingCommonToken(LINE_BREAK, "\n", 3),
  153. };
  154. assert_type(program_text, token_types);
  155. }
  156. public void test_token_stream8() {
  157. String program_text =
  158. "\r\nres.body = <<-_end_of_html_\n" +
  159. " _end_of_html_\n";
  160. TestingCommonToken[] token_types = {
  161. new TestingCommonToken(LINE_BREAK, "\n", 1),
  162. new TestingCommonToken(FUNCTION, "res", 2),
  163. new TestingCommonToken(DOT, ".", 2),
  164. new TestingCommonToken(FUNCTION, "body", 2),
  165. new TestingCommonToken(ASSIGN, "=", 2),
  166. new TestingCommonToken(HERE_DOC_BEGIN, "-_end_of_html_", 2),
  167. new TestingCommonToken(HERE_DOC_CONTENT, "", 2),
  168. new TestingCommonToken(LINE_BREAK, "\n", 3),
  169. };
  170. assert_type(program_text, token_types);
  171. }
  172. public void test_token_stream9() {
  173. String program_text = "\n\n\nunless /{$1}\\z/o =~ s";
  174. TestingCommonToken[] token_types = {
  175. new TestingCommonToken(LINE_BREAK, "\n", 1),
  176. new TestingCommonToken(LITERAL_unless, "unless", 4),
  177. new TestingCommonToken(REGEX, "{$1}\\z/o", 4),
  178. new TestingCommonToken(MATCH, "=~", 4),
  179. new TestingCommonToken(FUNCTION, "s", 4),
  180. };
  181. assert_type(program_text, token_types);
  182. }
  183. public void test_token_stream10() {
  184. String program_text = " when /^#/" +
  185. " raise \"unknown node type: '{ntype}'\"";
  186. TestingCommonToken[] token_types = {
  187. new TestingCommonToken(LITERAL_when, "when"),
  188. new TestingCommonToken(REGEX, "^#/"),
  189. new TestingCommonToken(FUNCTION, "raise"),
  190. new TestingCommonToken(DOUBLE_QUOTE_STRING, "unknown node type: '{ntype}'"),
  191. };
  192. assert_type(program_text, token_types);
  193. }
  194. public void test_token_stream11() {
  195. String program_text = "def log_src(src)\n" +
  196. " Logging::puts <<\"EOM\", src\n" +
  197. "checked program was:\n" +
  198. "/* begin */\n" +
  199. "%s/* end */\n\n"+
  200. "EOM\n" +
  201. "end";
  202. TestingCommonToken[] token_types = {
  203. new TestingCommonToken(LITERAL_def, "def"),
  204. new TestingCommonToken(FUNCTION, "log_src"),
  205. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  206. new TestingCommonToken(FUNCTION, "src"),
  207. new TestingCommonToken(RPAREN, ")"),
  208. new TestingCommonToken(LINE_BREAK, "\n"),
  209. new TestingCommonToken(CONSTANT, "Logging", 2),
  210. new TestingCommonToken(COLON2, "::", 2),
  211. new TestingCommonToken(FUNCTION, "puts", 2),
  212. new TestingCommonToken(HERE_DOC_BEGIN, "EOM", 2),
  213. new TestingCommonToken(HERE_DOC_CONTENT, "checked program was:\n/* begin */\n%s/* end */\n\n", 2),
  214. new TestingCommonToken(COMMA, ",", 7),
  215. new TestingCommonToken(FUNCTION, "src", 7),
  216. new TestingCommonToken(LINE_BREAK, "\n", 7),
  217. new TestingCommonToken(LITERAL_end, "end", 8),
  218. };
  219. assert_type(program_text, token_types);
  220. }
  221. public void test_token_stream12() {
  222. String program_text = "1%200";
  223. TestingCommonToken[] token_types = {
  224. new TestingCommonToken(INTEGER, "1"),
  225. new TestingCommonToken(MOD, "%"),
  226. new TestingCommonToken(INTEGER, "200"),
  227. };
  228. assert_type(program_text, token_types);
  229. }
  230. public void test_token_stream13() {
  231. String program_text = "; ;\t ;";
  232. TestingCommonToken[] token_types = {
  233. new TestingCommonToken(SEMI, ";"),
  234. };
  235. assert_type(program_text, token_types);
  236. }
  237. public void test_token_stream14() {
  238. String program_text = "a =1;a\n\n\n;;;;";
  239. TestingCommonToken[] token_types = {
  240. new TestingCommonToken(IDENTIFIER, "a"),
  241. new TestingCommonToken(ASSIGN, "="),
  242. new TestingCommonToken(INTEGER, "1"),
  243. new TestingCommonToken(SEMI, ";"),
  244. new TestingCommonToken(IDENTIFIER, "a"),
  245. //new TestingCommonToken(LINE_BREAK, "\n"),
  246. new TestingCommonToken(LINE_BREAK, "\n", 1),
  247. };
  248. assert_type(program_text, token_types);
  249. }
  250. public void test_token_stream15() {
  251. String program_text = "@numerator.to_f/@denominator.to_f";
  252. TestingCommonToken[] token_types = {
  253. new TestingCommonToken(INSTANCE_VARIABLE, "@numerator"),
  254. new TestingCommonToken(DOT, "."),
  255. new TestingCommonToken(FUNCTION, "to_f"),
  256. new TestingCommonToken(DIV, "/"),
  257. new TestingCommonToken(INSTANCE_VARIABLE, "@denominator"),
  258. new TestingCommonToken(DOT, "."),
  259. new TestingCommonToken(FUNCTION, "to_f"),
  260. };
  261. assert_type(program_text, token_types);
  262. }
  263. public void test_token_stream16() {
  264. String program_text = "sprintf(\"Rational(%s, %s)\", @numerator.inspect, @denominator.inspect)";
  265. TestingCommonToken[] token_types = {
  266. new TestingCommonToken(FUNCTION, "sprintf"),
  267. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  268. new TestingCommonToken(DOUBLE_QUOTE_STRING, "Rational(%s, %s)"),
  269. new TestingCommonToken(COMMA, ","),
  270. new TestingCommonToken(INSTANCE_VARIABLE, "@numerator"),
  271. new TestingCommonToken(DOT, "."),
  272. new TestingCommonToken(FUNCTION, "inspect"),
  273. new TestingCommonToken(COMMA, ","),
  274. new TestingCommonToken(INSTANCE_VARIABLE, "@denominator"),
  275. new TestingCommonToken(DOT, "."),
  276. new TestingCommonToken(FUNCTION, "inspect"),
  277. new TestingCommonToken(RPAREN, ")"),
  278. };
  279. assert_type(program_text, token_types);
  280. }
  281. public void test_token_stream17() {
  282. String program_text = "subj.gsub! /\\n/, \"\"\n";
  283. TestingCommonToken[] token_types = {
  284. new TestingCommonToken(FUNCTION, "subj"),
  285. new TestingCommonToken(DOT, "."),
  286. new TestingCommonToken(FUNCTION, "gsub!"),
  287. new TestingCommonToken(REGEX, "\\n/"),
  288. new TestingCommonToken(COMMA, ","),
  289. new TestingCommonToken(DOUBLE_QUOTE_STRING, ""),
  290. new TestingCommonToken(LINE_BREAK, "\n"),
  291. };
  292. assert_type(program_text, token_types);
  293. }
  294. public void test_token_stream18() {
  295. String program_text = "self / Rational.new!(a, 1)";
  296. TestingCommonToken[] token_types = {
  297. new TestingCommonToken(LITERAL_self, "self"),
  298. new TestingCommonToken(DIV, "/"),
  299. new TestingCommonToken(CONSTANT, "Rational"),
  300. new TestingCommonToken(DOT, "."),
  301. new TestingCommonToken(FUNCTION, "new!"),
  302. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  303. new TestingCommonToken(IDENTIFIER, "a"),
  304. new TestingCommonToken(COMMA, ","),
  305. new TestingCommonToken(INTEGER, "1"),
  306. new TestingCommonToken(RPAREN, ")"),
  307. };
  308. assert_type(program_text, token_types);
  309. }
  310. public void test_token_stream19() {
  311. String program_text = "session['key'].class";
  312. TestingCommonToken[] token_types = {
  313. new TestingCommonToken(FUNCTION, "session"),
  314. new TestingCommonToken(LBRACK_ARRAY_ACCESS, "["),
  315. new TestingCommonToken(SINGLE_QUOTE_STRING, "key"),
  316. new TestingCommonToken(RBRACK, "]"),
  317. new TestingCommonToken(DOT, "."),
  318. new TestingCommonToken(IDENTIFIER, "class"),
  319. };
  320. assert_type(program_text, token_types);
  321. }
  322. public void test_token_stream20() {
  323. String program_text = "$4.to_i.to_r / (10**$4.size)";
  324. TestingCommonToken[] token_types = {
  325. new TestingCommonToken(GLOBAL_VARIABLE , "$4"),
  326. new TestingCommonToken(DOT, "."),
  327. new TestingCommonToken(FUNCTION, "to_i"),
  328. new TestingCommonToken(DOT, "."),
  329. new TestingCommonToken(FUNCTION, "to_r"),
  330. new TestingCommonToken(DIV, "/"),
  331. new TestingCommonToken(LPAREN, "("),
  332. new TestingCommonToken(INTEGER, "10"),
  333. new TestingCommonToken(POWER, "**"),
  334. new TestingCommonToken(GLOBAL_VARIABLE , "$4"),
  335. new TestingCommonToken(DOT, "."),
  336. new TestingCommonToken(FUNCTION, "size"),
  337. new TestingCommonToken(RPAREN, ")"),
  338. };
  339. assert_type(program_text, token_types);
  340. }
  341. public void test_token_stream21() {
  342. String program_text = "def check_response_auth( res )\n" +
  343. "raise POPAuthenticationError, res unless /\\A\\+OK/i === res\n" +
  344. "res\n" +
  345. "end";
  346. TestingCommonToken[] token_types = {
  347. new TestingCommonToken(LITERAL_def, "def"),
  348. new TestingCommonToken(FUNCTION, "check_response_auth"),
  349. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  350. new TestingCommonToken(FUNCTION, "res"),
  351. new TestingCommonToken(RPAREN, ")"),
  352. new TestingCommonToken(LINE_BREAK, "\n"),
  353. new TestingCommonToken(FUNCTION, "raise", 2),
  354. new TestingCommonToken(CONSTANT, "POPAuthenticationError", 2),
  355. new TestingCommonToken(COMMA, ",", 2),
  356. new TestingCommonToken(FUNCTION, "res", 2),
  357. new TestingCommonToken(UNLESS_MODIFIER, "unless", 2),
  358. new TestingCommonToken(REGEX, "\\A\\+OK/i", 2),
  359. new TestingCommonToken(CASE_EQUAL, "===", 2),
  360. new TestingCommonToken(FUNCTION, "res", 2),
  361. new TestingCommonToken(LINE_BREAK, "\n", 2),
  362. new TestingCommonToken(FUNCTION, "res", 3),
  363. new TestingCommonToken(LINE_BREAK, "\n", 3),
  364. new TestingCommonToken(LITERAL_end, "end", 4),
  365. };
  366. assert_type(program_text, token_types);
  367. }
  368. public void test_token_stream22() {
  369. String program_text = "res.split(/ /)[1]";
  370. TestingCommonToken[] token_types = {
  371. new TestingCommonToken(FUNCTION, "res"),
  372. new TestingCommonToken(DOT, "."),
  373. new TestingCommonToken(FUNCTION, "split"),
  374. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  375. new TestingCommonToken(REGEX, " /"),
  376. new TestingCommonToken(RPAREN, ")"),
  377. new TestingCommonToken(LBRACK_ARRAY_ACCESS, "["),
  378. new TestingCommonToken(INTEGER, "1"),
  379. new TestingCommonToken(RBRACK, "]"),
  380. };
  381. assert_type(program_text, token_types);
  382. }
  383. public void test_token_stream23() {
  384. String program_text = "f(*a)";
  385. TestingCommonToken[] token_types = {
  386. new TestingCommonToken(FUNCTION, "f"),
  387. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "("),
  388. new TestingCommonToken(REST_ARG_PREFIX, "*"),
  389. new TestingCommonToken(FUNCTION, "a"),
  390. new TestingCommonToken(RPAREN, ")"),
  391. };
  392. assert_type(program_text, token_types);
  393. }
  394. public void test_token_stream24() {
  395. String program_text = "puts puts = 1";
  396. TestingCommonToken[] token_types = {
  397. new TestingCommonToken(FUNCTION, "puts"),
  398. new TestingCommonToken(IDENTIFIER, "puts"),
  399. new TestingCommonToken(ASSIGN, "="),
  400. new TestingCommonToken(INTEGER, "1"),
  401. };
  402. assert_type(program_text, token_types);
  403. }
  404. public void test_token_stream25() {
  405. String program_text = "def a; f do |element|\n" +
  406. " klass.module_eval(<<-EOC, __FILE__, __LINE__)\n" +
  407. " EOC\n" +
  408. " end\n" +
  409. " end";
  410. TestingCommonToken[] token_types = {
  411. new TestingCommonToken(LITERAL_def, "def"),
  412. new TestingCommonToken(FUNCTION, "a"),
  413. new TestingCommonToken(SEMI, ";"),
  414. new TestingCommonToken(FUNCTION, "f"),
  415. new TestingCommonToken(LITERAL_do, "do"),
  416. new TestingCommonToken(BOR, "|"),
  417. new TestingCommonToken(IDENTIFIER, "element"),
  418. new TestingCommonToken(BOR, "|"),
  419. new TestingCommonToken(LINE_BREAK, "\n"),
  420. new TestingCommonToken(FUNCTION, "klass", 2),
  421. new TestingCommonToken(DOT, ".", 2),
  422. new TestingCommonToken(FUNCTION, "module_eval", 2),
  423. new TestingCommonToken(LPAREN_WITH_NO_LEADING_SPACE, "(", 2),
  424. new TestingCommonToken(HERE_DOC_BEGIN, "-EOC", 2),
  425. new TestingCommonToken(HERE_DOC_CONTENT, "", 2),
  426. new TestingCommonToken(COMMA, ",", 3),
  427. new TestingCommonToken(LITERAL___FILE__, "__FILE__", 3),
  428. new TestingCommonToken(COMMA, ",", 3),
  429. new TestingCommonToken(LITERAL___LINE__, "__LINE__", 3),
  430. new TestingCommonToken(RPAREN, ")", 3),
  431. new TestingCommonToken(LINE_BREAK, "\n", 3),
  432. new TestingCommonToken(LITERAL_end, "end", 4),
  433. new TestingCommonToken(LINE_BREAK, "\n", 4),
  434. new TestingCommonToken(LITERAL_end, "end", 5),
  435. };
  436. assert_type(program_text, token_types);
  437. }
  438. public void test_token_stream26() {
  439. String program_text = ";if true then end";
  440. TestingCommonToken[] token_types = {
  441. new TestingCommonToken(SEMI, ";"),
  442. new TestingCommonToken(LITERAL_if, "if"),
  443. new TestingCommonToken(LITERAL_true, "true"),
  444. new TestingCommonToken(LITERAL_then, "then"),
  445. new TestingCommonToken(LITERAL_end, "end"),
  446. };
  447. assert_type(program_text, token_types);
  448. }
  449. public void test_token_stream27() {
  450. String program_text = "module_eval <<-\"end_eval\"\n end_eval\n";
  451. TestingCommonToken[] token_types = {
  452. new TestingCommonToken(FUNCTION, "module_eval"),
  453. new TestingCommonToken(HERE_DOC_BEGIN, "-end_eval"),
  454. new TestingCommonToken(HERE_DOC_CONTENT, ""),
  455. new TestingCommonToken(LINE_BREAK, "\n", 2),
  456. };
  457. assert_type(program_text, token_types);
  458. }
  459. public void test_token_stream28() {
  460. String program_text = "1...3";
  461. TestingCommonToken[] token_types = {
  462. new TestingCommonToken(INTEGER, "1"),
  463. new TestingCommonToken(EXCLUSIVE_RANGE, "..."),
  464. new TestingCommonToken(INTEGER, "3"),
  465. };
  466. assert_type(program_text, token_types);
  467. }
  468. public void test_token_stream29() {
  469. String program_text = "puts 1 rescue true";
  470. TestingCommonToken[] token_types = {
  471. new TestingCommonToken(FUNCTION, "puts"),
  472. new TestingCommonToken(INTEGER, "1"),
  473. new TestingCommonToken(RESCUE_MODIFIER, "rescue"),
  474. new TestingCommonToken(LITERAL_true, "true"),
  475. };
  476. assert_type(program_text, token_types);
  477. }
  478. public void test_token_stream30() {
  479. String program_text = "alias quo /";
  480. TestingCommonToken[] token_types = {
  481. new TestingCommonToken(LITERAL_alias, "alias"),
  482. new TestingCommonToken(FUNCTION, "quo"),
  483. new TestingCommonToken(DIV, "/"),
  484. };
  485. assert_type(program_text, token_types);
  486. }
  487. public void test_token_stream31() {
  488. String program_text = "print 1, <<EOF1, 2, <<EOF2, 3\n" +
  489. "EOF1\n" +
  490. "EOF2\n";
  491. TestingCommonToken[] token_types = {
  492. new TestingCommonToken(FUNCTION, "print"),
  493. new TestingCommonToken(INTEGER, "1"),
  494. new TestingCommonToken(COMMA, ","),
  495. new TestingCommonToken(HERE_DOC_BEGIN, "EOF1"),
  496. new TestingCommonToken(HERE_DOC_CONTENT, ""),
  497. new TestingCommonToken(COMMA, ",", 2),
  498. new TestingCommonToken(INTEGER, "2", 2),
  499. new TestingCommonToken(COMMA, ",", 2),
  500. new TestingCommonToken(HERE_DOC_BEGIN, "EOF2", 2),
  501. new TestingCommonToken(HERE_DOC_CONTENT, "", 2),
  502. new TestingCommonToken(COMMA, ",", 3),
  503. new TestingCommonToken(INTEGER, "3", 3),
  504. new TestingCommonToken(LINE_BREAK, "\n", 3),
  505. };
  506. assert_type(program_text, token_types);
  507. }
  508. /*need parser
  509. public void test_token_stream32() {
  510. String program_text = "print <<-EOF + \"#{'yyy'}\"\n" +
  511. " hey\n" +
  512. " EOF\n";
  513. TestingCommonToken[] token_types = {
  514. new TestingCommonToken(FUNCTION, "print"),
  515. new TestingCommonToken(HERE_DOC_BEGIN, "-EOF"),
  516. new TestingCommonToken(HERE_DOC_CONTENT, " hey\n"),
  517. new TestingCommonToken(PLUS, "+", 3),
  518. new TestingCommonToken(STRING_BEFORE_EXPRESSION_SUBSTITUTION, "", 3),
  519. new TestingCommonToken(LCURLY_BLOCK, "{", 3),
  520. new TestingCommonToken(SINGLE_QUOTE_STRING, "yyy", 3),
  521. new TestingCommonToken(RCURLY, "}", 3),
  522. new TestingCommonToken(STRING_BEFORE_EXPRESSION_SUBSTITUTION, "", 3),
  523. new TestingCommonToken(LINE_BREAK, "\n", 3),
  524. };
  525. assert_type(program_text, token_types);
  526. }*/
  527. /*
  528. public void test_defined_question_mark() {
  529. String program_text = "defined?";
  530. assert_type(program_text, 89);
  531. }
  532. */
  533. public void test_EmptyString() {
  534. String program_text = "";
  535. assert_type(program_text, Token.EOF_TYPE, null);
  536. }
  537. public void test_REGEX() {
  538. String[] program_texts = {
  539. "/\\r\\n\\r\\n/s",
  540. "/^#/",
  541. "/^Ruby the OOPL/",
  542. "/ruby/i",
  543. "/test|test/x",
  544. "/([\\300-\\367])/n",
  545. };
  546. String[] expected_texts = {
  547. "\\r\\n\\r\\n/s",
  548. "^#/",
  549. "^Ruby the OOPL/",
  550. "ruby/i",
  551. "test|test/x",
  552. "([\\300-\\367])/n",
  553. };
  554. assert_type(program_texts, REGEX, expected_texts);
  555. }
  556. public void test_R_REGEX() {
  557. String[] program_texts = {
  558. "%r{([^ \\t\\r\\n\\[\\{\\(])\\'}",
  559. "%r{test|test}",
  560. "%r/^Ruby the OOPL/",
  561. "%r|ruby|i",
  562. "%r/test|test/x",
  563. "%r{test|test}x",
  564. "%r(test|test)x",
  565. "%r[test|test]x",
  566. "%r(<b>(.*?)</b>)",
  567. "%r{}",
  568. };
  569. String[] expected_texts = {
  570. "([^ \\t\\r\\n\\[\\{\\(])\\'/",
  571. "test|test/",
  572. "^Ruby the OOPL/",
  573. "ruby/i",
  574. "test|test/x",
  575. "test|test/x",
  576. "test|test/x",
  577. "test|test/x",
  578. "<b>(.*?)</b>/",
  579. "/",
  580. };
  581. assert_type(program_texts, REGEX, expected_texts);
  582. }
  583. /*
  584. public void test_SINGLE_QUOTA() {
  585. String program_text = "`";
  586. assert_type(program_text, SINGLE_QUOTA);
  587. }*/
  588. public void test_QUESTION() {
  589. String program_text = "?";
  590. assert_type(program_text, QUESTION);
  591. }
  592. public void test_LPAREN() {
  593. String program_text = "(";
  594. assert_type(program_text, LPAREN);
  595. }
  596. public void test_RPAREN() {
  597. String program_text = ")";
  598. assert_type(program_text, RPAREN);
  599. }
  600. public void test_LBRACK() {
  601. String program_text = "[";
  602. assert_type(program_text, LBRACK);
  603. }
  604. public void test_RBRACK() {
  605. String program_text = "]";
  606. assert_type(program_text, RBRACK);
  607. }
  608. public void test_LCURLY() {
  609. String program_text = "{";
  610. assert_type(program_text, LCURLY_HASH);
  611. }
  612. public void test_RCURLY() {
  613. String program_text = "}";
  614. assert_type(program_text, RCURLY);
  615. }
  616. public void test_COLON() {
  617. String program_text = ":";
  618. assert_type(program_text, COLON_WITH_NO_FOLLOWING_SPACE);
  619. }
  620. public void test_COMMA() {
  621. String[] program_texts = {
  622. ",",
  623. ", ",
  624. ",\n",
  625. ", \n\n \n",
  626. };
  627. String[] expected_texts = {
  628. ",",
  629. ",",
  630. ",",
  631. ",",
  632. };
  633. assert_type(program_texts, COMMA, expected_texts);
  634. }
  635. public void test_ASSIGN() {
  636. String program_text = "=";
  637. assert_type(program_text, ASSIGN);
  638. }
  639. public void test_PLUS_ASSIGN() {
  640. String program_text = "+=";
  641. assert_type(program_text, PLUS_ASSIGN);
  642. }
  643. public void test_MINUS_ASSIGN() {
  644. String program_text = "-=";
  645. assert_type(program_text, MINUS_ASSIGN);
  646. }
  647. public void test_STAR_ASSIGN() {
  648. String program_text = "*=";
  649. assert_type(program_text, STAR_ASSIGN);
  650. }
  651. /*
  652. public void test_DIV_ASSIGN() {
  653. String program_text = "/=";
  654. assert_type(program_text, DIV_ASSIGN);
  655. }
  656. */
  657. public void test_MOD_ASSIGN() {
  658. String program_text = "%=";
  659. assert_type(program_text, MOD_ASSIGN);
  660. }
  661. public void test_POWER_ASSIGN() {
  662. String program_text = "**=";
  663. assert_type(program_text, POWER_ASSIGN);
  664. }
  665. public void test_BAND_ASSIGN() {
  666. String program_text = "&=";
  667. assert_type(program_text, BAND_ASSIGN);
  668. }
  669. public void test_BXOR_ASSIGNN() {
  670. String program_text = "^=";
  671. assert_type(program_text, BXOR_ASSIGN);
  672. }
  673. public void test_BOR_ASSIGNN() {
  674. String program_text = "|=";
  675. assert_type(program_text, BOR_ASSIGN);
  676. }
  677. /*
  678. public void test_LEFT_SHIFT_ASSIGN() {
  679. String program_text = "<<=";
  680. assert_type(program_text, LEFT_SHIFT_ASSIGN);
  681. }
  682. */
  683. public void test_RIGHT_SHIFT_ASSIGN() {
  684. String program_text = ">>=";
  685. assert_type(program_text, RIGHT_SHIFT_ASSIGN);
  686. }
  687. public void test_LOGICAL_AND_ASSIGN() {
  688. String program_text = "&&=";
  689. assert_type(program_text, LOGICAL_AND_ASSIGN);
  690. }
  691. public void test_LOGICAL_OR_ASSIGN() {
  692. String program_text = "||=";
  693. assert_type(program_text, LOGICAL_OR_ASSIGN);
  694. }
  695. public void test_NOT() {
  696. String program_text = "!";
  697. assert_type(program_text, NOT);
  698. }
  699. public void test_BNOT() {
  700. String program_text = "~";
  701. assert_type(program_text, BNOT);
  702. }
  703. public void test_DIV() {
  704. String program_text = "/";
  705. assert_type(program_text, DIV);
  706. }
  707. public void test_PLUS() {
  708. String program_text = "+";
  709. assert_type(program_text, UNARY_PLUS);
  710. }
  711. /*
  712. public void test_MOD() {
  713. String program_text = "%";
  714. assert_type(program_text, MOD);
  715. }
  716. */
  717. public void test_MINUS() {
  718. String program_text = "-";
  719. assert_type(program_text, UNARY_MINUS);
  720. }
  721. public void test_STAR() {
  722. String program_text = "*";
  723. assert_type(program_text, REST_ARG_PREFIX);
  724. }
  725. public void test_LESS_THAN() {
  726. String program_text = "<";
  727. assert_type(program_text, LESS_THAN);
  728. }
  729. public void test_GREATER_THAN() {
  730. String program_text = ">";
  731. assert_type(program_text, GREATER_THAN);
  732. }
  733. public void test_BXOR() {
  734. String program_text = "^";
  735. assert_type(program_text, BXOR);
  736. }
  737. public void test_BOR() {
  738. String program_text = "|";
  739. assert_type(program_text, BOR);
  740. }
  741. public void test_LOGICAL_OR() {
  742. String program_text = "||";
  743. assert_type(program_text, LOGICAL_OR);
  744. }
  745. public void test_LOGICAL_AND() {
  746. String program_text = "&&";
  747. assert_type(program_text, LOGICAL_AND);
  748. }
  749. public void test_BAND() {
  750. String program_text = "&";
  751. assert_type(program_text, BLOCK_ARG_PREFIX);
  752. }
  753. public void test_SEMI() {
  754. String[] program_texts = {
  755. ";",
  756. ";;;",
  757. };
  758. String[] expected_texts = {
  759. ";",
  760. ";",
  761. };
  762. assert_type(program_texts, SEMI, expected_texts);
  763. }
  764. public void test_SEMI_as_LINEBREAK() {
  765. String[] program_texts = {
  766. "\n \n\t\n\n;\n;",
  767. ";\n\n\n",
  768. ";; ;;\n;;\n\n;;",
  769. };
  770. String[] expected_texts = {
  771. "\n",
  772. ";",
  773. ";",
  774. };
  775. assert_type(program_texts, LINE_BREAK, expected_texts);
  776. }
  777. public void test_ASSOC() {
  778. String program_text = "=>";
  779. assert_type(program_text, ASSOC);
  780. }
  781. public void test_INCLUSIVE_RANGE() {
  782. String program_text = "..";
  783. assert_type(program_text, INCLUSIVE_RANGE);
  784. }
  785. public void test_EXCLUSIVE_RANGE() {
  786. String program_text = "...";
  787. assert_type(program_text, EXCLUSIVE_RANGE);
  788. }
  789. public void test_POWER() {
  790. String program_text = "**";
  791. assert_type(program_text, POWER);
  792. }
  793. public void test_COMPARE() {
  794. String program_text = "<=>";
  795. assert_type(program_text, COMPARE);
  796. }
  797. public void test_GREATER_OR_EQUAL() {
  798. String program_text = ">=";
  799. assert_type(program_text, GREATER_OR_EQUAL);
  800. }
  801. public void test_LESS_OR_EQUAL() {
  802. String program_text = "<=";
  803. assert_type(program_text, LESS_OR_EQUAL);
  804. }
  805. public void test_EQUAL() {
  806. String program_text = "==";
  807. assert_type(program_text, EQUAL);
  808. }
  809. public void test_CASE_EQUAL() {
  810. String program_text = "===";
  811. assert_type(program_text, CASE_EQUAL);
  812. }
  813. public void test_NOT_EQUAL() {
  814. String program_text = "!=";
  815. assert_type(program_text, NOT_EQUAL);
  816. }
  817. public void test_MATCH() {
  818. String program_text = "=~";
  819. assert_type(program_text, MATCH);
  820. }
  821. public void test_NOT_MATCH() {
  822. String program_text = "!~";
  823. assert_type(program_text, NOT_MATCH);
  824. }
  825. public void test_LEFT_SHIFT() {
  826. String program_text = "<<";
  827. assert_type(program_text, LEFT_SHIFT);
  828. }
  829. public void test_RIGHT_SHIFT() {
  830. String program_text = ">>";
  831. assert_type(program_text, RIGHT_SHIFT);
  832. }
  833. public void test_COLON2() {
  834. String program_text = "::";
  835. assert_type(program_text, LEADING_COLON2);
  836. }
  837. public void test_LINE_BREAK() {
  838. String[] program_texts = {
  839. "\r",
  840. "\n",
  841. "\r\n",
  842. "\n\n\n\n\n",
  843. "\r\n\n\r\n\n\n\r\n\r\n",
  844. };
  845. String[] expected_texts = {
  846. "",
  847. "\n",
  848. "\n",
  849. "\n",
  850. "\n",
  851. };
  852. assert_type(program_texts, LINE_BREAK, expected_texts);
  853. }
  854. public void test_FUNCTION() {
  855. String[] program_texts = {
  856. "puts",
  857. "print",
  858. };
  859. assert_type(program_texts, FUNCTION);
  860. }
  861. public void test_IDENTIFIER () {
  862. String[] program_texts = {
  863. "hey",
  864. "_",
  865. "_1",
  866. "_a",
  867. "abc123",
  868. "_________aaaaaaa11111111111____________ZZZZZZZZZ00000000000",
  869. "_ab1",
  870. };
  871. assert_type(program_texts, FUNCTION);
  872. }
  873. public void test_PREDICATE_FUNCTION() {
  874. String[] program_texts = {
  875. "hey?",
  876. "_?",
  877. "_1?",
  878. "_a?",
  879. "_________aaaaaaa11111111111____________ZZZZZZZZZ00000000000?",
  880. "_2b2abC?",
  881. };
  882. assert_type(program_texts, FUNCTION);
  883. }
  884. public void test_DESTRUCTIVE_FUNCTION() {
  885. String[] program_texts = {
  886. "hey!",
  887. "_!",
  888. "_1!",
  889. "_a!",
  890. "_________aaaaaaa11111111111____________ZZZZZZZZZ00000000000!",
  891. "_1abC!",
  892. };
  893. assert_type(program_texts, FUNCTION);
  894. }
  895. public void test_GLOBAL_VARIABLE () {
  896. String[] program_texts = {
  897. "$-#",
  898. "$-",
  899. "$-K",
  900. "$A",
  901. "$a",
  902. "$aBC12_",
  903. "$_",
  904. "$__",
  905. "$a234",
  906. "$&",
  907. "$`",
  908. "$\\",
  909. "$+",
  910. "$1",
  911. "$2",
  912. "$3",
  913. "$4",
  914. "$5",
  915. "$6",
  916. "$7",
  917. "$8",
  918. "$9",
  919. "$123456",
  920. };
  921. assert_type(program_texts, GLOBAL_VARIABLE );
  922. }
  923. public void test_INSTANCE_VARIABLE() {
  924. String[] program_texts = {
  925. "@A",
  926. "@a",
  927. "@aBC12_",
  928. "@_",
  929. };
  930. assert_type(program_texts, INSTANCE_VARIABLE);
  931. }
  932. public void test_CLASS_VARIABLE() {
  933. String[] program_texts = {
  934. "@@A",
  935. "@@a",
  936. "@@aBC12_",
  937. "@@_",
  938. };
  939. assert_type(program_texts, CLASS_VARIABLE);
  940. }
  941. public void test_CONSTANT() {
  942. String[] program_texts = {
  943. "A",
  944. "Z",
  945. "A_",
  946. "Abc",
  947. "B2",
  948. "PI",
  949. "MyClass3",
  950. };
  951. assert_type(program_texts, CONSTANT);
  952. }
  953. public void test_INTEGER() {
  954. String[] program_texts = {
  955. "123456",
  956. "1",
  957. "543",
  958. "0",
  959. "123_456",
  960. "123_456_789_123_345_789",
  961. };
  962. String[] expected_texts = {
  963. "123456",
  964. "1",
  965. "543",
  966. "0",
  967. "123456",
  968. "123456789123345789",
  969. };
  970. assert_type(program_texts, INTEGER, expected_texts);
  971. }
  972. public void test_HEX() {
  973. String[] program_texts = {
  974. "0xaabbC",
  975. "0X0abb1",
  976. };
  977. String[] expected_texts = {
  978. "aabbC",
  979. "0abb1",
  980. };
  981. assert_type(program_texts, HEX, expected_texts);
  982. }
  983. public void test_OCTAL() {
  984. String[] program_texts = {
  985. "0377",
  986. };
  987. String[] expected_texts = {
  988. "377",
  989. };
  990. assert_type(program_texts, OCTAL, expected_texts);
  991. }
  992. public void test_BINARY() {
  993. String[] program_texts = {
  994. "0b1010",
  995. "0B0100",
  996. "0b001_001",
  997. };
  998. String[] expected_texts = {
  999. "1010",
  1000. "0100",
  1001. "001001",
  1002. };
  1003. assert_type(program_texts, BINARY, expected_texts);
  1004. }
  1005. public void test_ASCII_VALUE() {
  1006. String[] program_texts = {
  1007. "?&",
  1008. "?a",
  1009. "?\"",
  1010. "?\\n",
  1011. "?\\s",
  1012. "?\\C-a",
  1013. "?\\M-a",
  1014. "?\\M-\\C-a",
  1015. "?\\C-?",
  1016. };
  1017. assert_type(program_texts, ASCII_VALUE);
  1018. }
  1019. public void test_FLOAT() {
  1020. String[] program_texts = {
  1021. ".1",
  1022. ".00",
  1023. "12.34",
  1024. "12.0",
  1025. "0.2E2",
  1026. ".1234E2",
  1027. ".0234E+2",
  1028. ".1234e-2",
  1029. "1234e-2",
  1030. "1234E-21",
  1031. "0.0",
  1032. "1e3",
  1033. "2e18",
  1034. "2E-18",
  1035. };
  1036. assert_type(program_texts, FLOAT);
  1037. }
  1038. public void test_DOT() {
  1039. String program_texts = ".";
  1040. assert_type(program_texts, DOT);
  1041. }
  1042. public void test_DOUBLE_QUOTE_STRING_LITERAL() {
  1043. String[] program_texts = {
  1044. "\"Rational(%s, %s)\"",
  1045. "\"%Y-%m-%d %H:%M:%S\"",
  1046. "\"\"",
  1047. "\" \"",
  1048. "\"string\"",
  1049. "\"hello\"",
  1050. "\" this is a string \"",
  1051. "\"2\"",
  1052. "\"\\\\\"",
  1053. "\"\\n\"",
  1054. "\"/usr/local\"",
  1055. "\"\\360\"",
  1056. "\"hello\n world\"",
  1057. };
  1058. String[] expected_texts = {
  1059. "Rational(%s, %s)",
  1060. "%Y-%m-%d %H:%M:%S",
  1061. "",
  1062. " ",
  1063. "string",
  1064. "hello",
  1065. " this is a string ",
  1066. "2",
  1067. "\\\\",
  1068. "\\n",
  1069. "/usr/local",
  1070. "\\360",
  1071. "hello\n world",
  1072. };
  1073. assert_type(program_texts, DOUBLE_QUOTE_STRING, expected_texts);
  1074. }
  1075. public void test_COMMAND_OUTPUT() {
  1076. String[] program_texts = {
  1077. "``",
  1078. "` `",
  1079. "`command`",
  1080. "` this is a command `",
  1081. "`2`",
  1082. "`\\\\`",
  1083. "`\\n`",
  1084. };
  1085. String[] expected_texts = {
  1086. "",
  1087. " ",
  1088. "command",
  1089. " this is a command ",
  1090. "2",
  1091. "\\\\",
  1092. "\\n",
  1093. };
  1094. assert_type(program_texts, COMMAND_OUTPUT, expected_texts);
  1095. }
  1096. public void test_X_COMMAND_OUTPUT() {
  1097. String[] program_texts = {
  1098. "%x/^Ruby the OOPL/",
  1099. "%x|ruby|",
  1100. "%x/test|test/",
  1101. "%x{test|test}",
  1102. "%x(test|test)",
  1103. "%x[test|test]",
  1104. };
  1105. String[] expected_texts = {
  1106. "^Ruby the OOPL",
  1107. "ruby",
  1108. "test|test",
  1109. "test|test",
  1110. "test|test",
  1111. "test|test",
  1112. };
  1113. assert_type(program_texts, COMMAND_OUTPUT, expected_texts);
  1114. }
  1115. public void test_SINGLE_QUOTE_STRING_LITERAL() {
  1116. String[] program_texts = {
  1117. "\'\'",
  1118. "\' \'",
  1119. "\'string\'",
  1120. "\' this is a #@string \'",
  1121. "\'2\'",
  1122. "\'\\\\\'",
  1123. "\'\\n\'",
  1124. "\'hello\n #{world}\'",
  1125. };
  1126. String[] expected_texts = {
  1127. "",
  1128. " ",
  1129. "string",
  1130. " this is a #@string ",
  1131. "2",
  1132. "\\\\",
  1133. "\\n",
  1134. "hello\n #{world}",
  1135. };
  1136. assert_type(program_texts, SINGLE_QUOTE_STRING, expected_texts);
  1137. }
  1138. public void test_q_STRING() {
  1139. String[] program_texts = {
  1140. "%q!test string!",
  1141. "%q//",
  1142. "%q# #",
  1143. "%q$string$'",
  1144. "%q^ this is a string ^",
  1145. };
  1146. String[] expected_texts = {
  1147. "test string",
  1148. "",
  1149. " ",
  1150. "string",
  1151. " this is a string ",
  1152. };
  1153. assert_type(program_texts, SINGLE_QUOTE_STRING, expected_texts);
  1154. }
  1155. public void test_Q_STRING() {
  1156. String[] program_texts = {
  1157. "%/test string/",
  1158. "%Q/test string/",
  1159. "%Q\ntest string\n",
  1160. "%Q*2*",
  1161. "%Q(\\\\)",
  1162. "%Q{\\\\}",
  1163. "%Q[\\\\]",
  1164. "%Q]\\\\]",
  1165. "%Q}\\\\}",
  1166. "%Q)\\\\)",
  1167. "%Q!\\n!",
  1168. };
  1169. String[] expected_texts = {
  1170. "test string",
  1171. "test string",
  1172. "test string",
  1173. "2",
  1174. "\\\\",
  1175. "\\\\",
  1176. "\\\\",
  1177. "\\\\",
  1178. "\\\\",
  1179. "\\\\",
  1180. "\\n",
  1181. };
  1182. assert_type(program_texts, DOUBLE_QUOTE_STRING, expected_texts);
  1183. }
  1184. public void test_COMMENT() {
  1185. String[] program_texts = {
  1186. "#",
  1187. "# ",
  1188. "# ",
  1189. "#12424scvdsfv",
  1190. "#4r fgr rt",
  1191. "#winClicker",
  1192. };
  1193. String[] expected_texts = {
  1194. null,
  1195. null,
  1196. null,
  1197. null,
  1198. null,
  1199. null,
  1200. };
  1201. assert_type(program_texts, Token.EOF_TYPE, expected_texts);
  1202. }
  1203. public void test_WHITE_SPACE() {
  1204. String[] program_texts = {
  1205. " ",
  1206. "\t",
  1207. " ",
  1208. "\t\t\t\t\t",
  1209. " \t\t \t",
  1210. };
  1211. String[] expected_texts = {
  1212. null,
  1213. null,
  1214. null,
  1215. null,
  1216. null,
  1217. };
  1218. assert_type(program_texts, Token.EOF_TYPE, expected_texts);
  1219. }
  1220. public void test_LINE_CONTINUATION() {
  1221. String[] program_texts = {
  1222. "\\\n",
  1223. };
  1224. String[] expected_texts = {
  1225. null,
  1226. };
  1227. assert_type(program_texts, Token.EOF_TYPE, expected_texts);
  1228. }
  1229. /*public void test_HERE_DOC_BEGIN() {
  1230. String[] program_texts = {
  1231. "<<EOF\nThe price is #{$Price}.\nEOF\n",
  1232. "-<<123456\nThe\n price\n is #{$Price}.\n123456\n",
  1233. "<<!@#$%^&*\nThe price is\n #{$Price}.\n!@#$%^&*\n",
  1234. };
  1235. String[] expected_texts = {
  1236. "The price is #{$Price}.\n",
  1237. "The\n price\n is #{$Price}.\n",
  1238. "The price is\n #{$Price}.\n",
  1239. };
  1240. assert_type(program_texts, HERE_DOC_BEGIN, expected_texts);
  1241. }*/
  1242. public void test_RDOC() {
  1243. String[] program_texts = {
  1244. "=begin\n=end",
  1245. "=begin\nwhatever\n=end",
  1246. "=begin\nwha\n\n%^$%^$%$^&$%\n\n&tever\n=end",
  1247. };
  1248. String[] expected_texts = {
  1249. null,
  1250. null,
  1251. null,
  1252. };
  1253. assert_type(program_texts, Token.EOF_TYPE, expected_texts);
  1254. }
  1255. public void test_W_ARRAY() {
  1256. String[] program_texts = {
  1257. "%w(folder openfold)",
  1258. "%w/test string/",
  1259. "%W!test string!",
  1260. "%w\ntest string\n",
  1261. "%W&Seconds/day: #{24*60*60}&",
  1262. "%w//",
  1263. "%w# #",
  1264. "%w$string$'",
  1265. "%W^ this is a string ^",
  1266. "%W*2*",
  1267. "%W(\\\\)",
  1268. "%w{\\\\}",
  1269. "%w[\\\\]",
  1270. "%w]\\\\]",
  1271. "%w}\\\\}",
  1272. "%w)\\\\)",
  1273. "%W!\\n!",
  1274. };
  1275. String[] expected_texts = {
  1276. "folder openfold",
  1277. "test string",
  1278. "test string",
  1279. "test string",

Large files files are truncated, but you can click here to view the full file