all repos — NoPaste @ 5c12c8a8f515faa64a6cd1d3f04d9aa60561322d

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/php/test.js (view raw)

  1// CodeMirror, copyright (c) by Marijn Haverbeke and others
  2// Distributed under an MIT license: https://codemirror.net/LICENSE
  3
  4(function() {
  5  var mode = CodeMirror.getMode({indentUnit: 2}, "php");
  6  function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  7
  8  MT('simple_test',
  9     '[meta <?php] ' +
 10     '[keyword echo] [string "aaa"]; ' +
 11     '[meta ?>]');
 12
 13  MT('variable_interpolation_non_alphanumeric',
 14     '[meta <?php]',
 15     '[keyword echo] [string "aaa$~$!$@$#$$$%$^$&$*$($)$.$<$>$/$\\$}$\\\"$:$;$?$|$[[$]]$+$=aaa"]',
 16     '[meta ?>]');
 17
 18  MT('variable_interpolation_digits',
 19     '[meta <?php]',
 20     '[keyword echo] [string "aaa$1$2$3$4$5$6$7$8$9$0aaa"]',
 21     '[meta ?>]');
 22
 23  MT('variable_interpolation_simple_syntax_1',
 24     '[meta <?php]',
 25     '[keyword echo] [string "aaa][variable-2 $aaa][string .aaa"];',
 26     '[meta ?>]');
 27
 28  MT('variable_interpolation_simple_syntax_2',
 29     '[meta <?php]',
 30     '[keyword echo] [string "][variable-2 $aaaa][[','[number 2]',         ']][string aa"];',
 31     '[keyword echo] [string "][variable-2 $aaaa][[','[number 2345]',      ']][string aa"];',
 32     '[keyword echo] [string "][variable-2 $aaaa][[','[number 2.3]',       ']][string aa"];',
 33     '[keyword echo] [string "][variable-2 $aaaa][[','[variable aaaaa]',   ']][string aa"];',
 34     '[keyword echo] [string "][variable-2 $aaaa][[','[variable-2 $aaaaa]',']][string aa"];',
 35
 36     '[keyword echo] [string "1aaa][variable-2 $aaaa][[','[number 2]',         ']][string aa"];',
 37     '[keyword echo] [string "aaa][variable-2 $aaaa][[','[number 2345]',      ']][string aa"];',
 38     '[keyword echo] [string "aaa][variable-2 $aaaa][[','[number 2.3]',       ']][string aa"];',
 39     '[keyword echo] [string "aaa][variable-2 $aaaa][[','[variable aaaaa]',   ']][string aa"];',
 40     '[keyword echo] [string "aaa][variable-2 $aaaa][[','[variable-2 $aaaaa]',']][string aa"];',
 41     '[meta ?>]');
 42
 43  MT('variable_interpolation_simple_syntax_3',
 44     '[meta <?php]',
 45     '[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string .aaaaaa"];',
 46     '[keyword echo] [string "aaa][variable-2 $aaaa][string ->][variable-2 $aaaaa][string .aaaaaa"];',
 47     '[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string [[2]].aaaaaa"];',
 48     '[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string ->aaaa2.aaaaaa"];',
 49     '[meta ?>]');
 50
 51  MT('variable_interpolation_escaping',
 52     '[meta <?php] [comment /* Escaping */]',
 53     '[keyword echo] [string "aaa\\$aaaa->aaa.aaa"];',
 54     '[keyword echo] [string "aaa\\$aaaa[[2]]aaa.aaa"];',
 55     '[keyword echo] [string "aaa\\$aaaa[[asd]]aaa.aaa"];',
 56     '[keyword echo] [string "aaa{\\$aaaa->aaa.aaa"];',
 57     '[keyword echo] [string "aaa{\\$aaaa[[2]]aaa.aaa"];',
 58     '[keyword echo] [string "aaa{\\aaaaa[[asd]]aaa.aaa"];',
 59     '[keyword echo] [string "aaa\\${aaaa->aaa.aaa"];',
 60     '[keyword echo] [string "aaa\\${aaaa[[2]]aaa.aaa"];',
 61     '[keyword echo] [string "aaa\\${aaaa[[asd]]aaa.aaa"];',
 62     '[meta ?>]');
 63
 64  MT('variable_interpolation_complex_syntax_1',
 65     '[meta <?php]',
 66     '[keyword echo] [string "aaa][variable-2 $]{[variable aaaa]}[string ->aaa.aaa"];',
 67     '[keyword echo] [string "aaa][variable-2 $]{[variable-2 $aaaa]}[string ->aaa.aaa"];',
 68     '[keyword echo] [string "aaa][variable-2 $]{[variable-2 $aaaa][[','  [number 42]',']]}[string ->aaa.aaa"];',
 69     '[keyword echo] [string "aaa][variable-2 $]{[variable aaaa][meta ?>]aaaaaa');
 70
 71  MT('variable_interpolation_complex_syntax_2',
 72     '[meta <?php] [comment /* Monsters */]',
 73     '[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*}?>} $aaa<?php } */]}[string ->aaa.aaa"];',
 74     '[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*}?>*/][[','  [string "aaa][variable-2 $aaa][string {}][variable-2 $]{[variable aaa]}[string "]',']]}[string ->aaa.aaa"];',
 75     '[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*} } $aaa } */]}[string ->aaa.aaa"];');
 76
 77
 78  function build_recursive_monsters(nt, t, n){
 79    var monsters = [t];
 80    for (var i = 1; i <= n; ++i)
 81      monsters[i] = nt.join(monsters[i - 1]);
 82    return monsters;
 83  }
 84
 85  var m1 = build_recursive_monsters(
 86    ['[string "][variable-2 $]{[variable aaa] [operator +] ', '}[string "]'],
 87    '[comment /* }?>} */] [string "aaa][variable-2 $aaa][string .aaa"]',
 88    10
 89  );
 90
 91  MT('variable_interpolation_complex_syntax_3_1',
 92     '[meta <?php] [comment /* Recursive monsters */]',
 93     '[keyword echo] ' + m1[4] + ';',
 94     '[keyword echo] ' + m1[7] + ';',
 95     '[keyword echo] ' + m1[8] + ';',
 96     '[keyword echo] ' + m1[5] + ';',
 97     '[keyword echo] ' + m1[1] + ';',
 98     '[keyword echo] ' + m1[6] + ';',
 99     '[keyword echo] ' + m1[9] + ';',
100     '[keyword echo] ' + m1[0] + ';',
101     '[keyword echo] ' + m1[10] + ';',
102     '[keyword echo] ' + m1[2] + ';',
103     '[keyword echo] ' + m1[3] + ';',
104     '[keyword echo] [string "end"];',
105     '[meta ?>]');
106
107  var m2 = build_recursive_monsters(
108    ['[string "a][variable-2 $]{[variable aaa] [operator +] ', ' [operator +] ', '}[string .a"]'],
109    '[comment /* }?>{{ */] [string "a?>}{{aa][variable-2 $aaa][string .a}a?>a"]',
110    5
111  );
112
113  MT('variable_interpolation_complex_syntax_3_2',
114     '[meta <?php] [comment /* Recursive monsters 2 */]',
115     '[keyword echo] ' + m2[0] + ';',
116     '[keyword echo] ' + m2[1] + ';',
117     '[keyword echo] ' + m2[5] + ';',
118     '[keyword echo] ' + m2[4] + ';',
119     '[keyword echo] ' + m2[2] + ';',
120     '[keyword echo] ' + m2[3] + ';',
121     '[keyword echo] [string "end"];',
122     '[meta ?>]');
123
124  function build_recursive_monsters_2(mf1, mf2, nt, t, n){
125    var monsters = [t];
126    for (var i = 1; i <= n; ++i)
127      monsters[i] = nt[0] + mf1[i - 1] + nt[1] + mf2[i - 1] + nt[2] + monsters[i - 1] + nt[3];
128    return monsters;
129  }
130
131  var m3 = build_recursive_monsters_2(
132    m1,
133    m2,
134    ['[string "a][variable-2 $]{[variable aaa] [operator +] ', ' [operator +] ', ' [operator +] ', '}[string .a"]'],
135    '[comment /* }?>{{ */] [string "a?>}{{aa][variable-2 $aaa][string .a}a?>a"]',
136    4
137  );
138
139  MT('variable_interpolation_complex_syntax_3_3',
140     '[meta <?php] [comment /* Recursive monsters 2 */]',
141     '[keyword echo] ' + m3[4] + ';',
142     '[keyword echo] ' + m3[0] + ';',
143     '[keyword echo] ' + m3[3] + ';',
144     '[keyword echo] ' + m3[1] + ';',
145     '[keyword echo] ' + m3[2] + ';',
146     '[keyword echo] [string "end"];',
147     '[meta ?>]');
148
149  MT("variable_interpolation_heredoc",
150     "[meta <?php]",
151     "[string <<<here]",
152     "[string doc ][variable-2 $]{[variable yay]}[string more]",
153     "[string here]; [comment // normal]");
154})();