Last active
June 18, 2019 02:27
-
-
Save tshort/183d3d2095ae0945b937f660c9df4808 to your computer and use it in GitHub Desktop.
Tests for syntax highlighting of embedded languages in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fun(a, b) | |
# hello World | |
return a + b # hi | |
end | |
""" | |
Hello World | |
""" | |
############################################################### | |
# Python: big test | |
############################################################### | |
py""" # source from: https://github.com/hdima/python-syntax/blob/69760cb3accce488cc072772ca918ac2cbf384ba/test.py#L1 | |
# Comments. | |
a = $(embedded) + 3.3 | |
# TODO FIXME XXX | |
# Keywords. | |
with break continue del exec return pass print raise global assert lambda yield | |
for while if elif else import from as try except finally and in is not or | |
yield from | |
def functionname | |
class Classname | |
def функция | |
class Класс | |
await | |
async def Test | |
async with | |
async for | |
# Builtin objects. | |
True False Ellipsis None NotImplemented | |
# Builtin function and types. | |
__import__ abs all any apply basestring bool buffer callable chr classmethod | |
cmp coerce compile complex delattr dict dir divmod enumerate eval execfile file | |
filter float frozenset getattr globals hasattr hash help hex id input int | |
intern isinstance issubclass iter len list locals long map max min object oct | |
open ord pow property range raw_input reduce reload repr reversed round set | |
setattr slice sorted staticmethod str sum super tuple type unichr unicode vars | |
xrange zip | |
# Builtin exceptions and warnings. | |
BaseException Exception StandardError ArithmeticError LookupError | |
EnvironmentError | |
AssertionError AttributeError EOFError FloatingPointError GeneratorExit IOError | |
ImportError IndexError KeyError KeyboardInterrupt MemoryError NameError | |
NotImplementedError OSError OverflowError ReferenceError RuntimeError | |
StopIteration SyntaxError IndentationError TabError SystemError SystemExit | |
TypeError UnboundLocalError UnicodeError UnicodeEncodeError UnicodeDecodeError | |
UnicodeTranslateError ValueError WindowsError ZeroDivisionError | |
Warning UserWarning DeprecationWarning PendingDepricationWarning SyntaxWarning | |
RuntimeWarning FutureWarning ImportWarning UnicodeWarning | |
# Decorators. | |
@ decoratorname | |
@ object.__init__(arg1, arg2) | |
@ декоратор | |
@ декоратор.décorateur | |
# Numbers | |
0 1 2 9 10 0x1f .3 12.34 0j 0j 34.2E-3 0b10 0o77 1023434 0x0 | |
# Erroneous numbers | |
077 100L 0xfffffffL 0L 08 0xk 0x 0b102 0o78 0o123LaB | |
# Strings | |
" test " ' test ' | |
''' | |
test | |
''' | |
" \a\b\c\"\'\n\r \x34\077 \08 \xag" | |
r" \" \' " | |
"testтест" | |
b"test" | |
b"test\r\n\xffff" | |
b"тестtest" | |
br"test" | |
br"\a\b\n\r" | |
# Formattings | |
" %f " | |
b" %f " | |
"{0.name!r:b} {0[n]} {name!s: } {{test}} {{}} {} {.__len__:s}" | |
b"{0.name!r:b} {0[n]} {name!s: } {{test}} {{}} {} {.__len__:s}" | |
"${test} ${test ${test}aname $$$ $test+nope" | |
b"${test} ${test ${test}aname $$$ $test+nope" | |
# Doctests. | |
''' | |
Test: | |
>>> a = 5 | |
>>> a | |
5 | |
Test | |
''' | |
# Erroneous symbols or bad variable names. | |
$ ? 6xav | |
&& || === | |
# Indentation errors. | |
break | |
# Trailing space errors. | |
break | |
""" | |
# Back-to-Julia test | |
function fun(a, b) | |
# hello World | |
return a + b # hi | |
end | |
""" | |
Hello World | |
""" | |
############################################################### | |
# Python: little tests | |
############################################################### | |
a = py" a = fun('a', 1.23) " | |
a = py" a = fun('a', 1.23) " | |
a = py""" a = fun('a', "b", 1.23) """ | |
a = py""" a = fun('a', "b", 1.23) """ | |
a = py""" a = fun('a', "b", 1.23) """ | |
############################################################### | |
# R: big test | |
############################################################### | |
R""" # from https://highlightjs.org/static/demo/ | |
library(ggplot2) | |
centre <- function(x, type, ...) { | |
switch(type, | |
mean = mean(x), | |
median = median(x), | |
trimmed = mean(x, trim = .1)) | |
} | |
myVar1 | |
myVar.2 | |
data$x | |
foo "bar" baz | |
# test "test" | |
"test # test" | |
(123) (1) (10) (0.1) (.2) (1e-7) | |
(1.2e+7) (2e) (3e+10) (0x0) (0xa) | |
(0xabcdef1234567890) (123L) (1L) | |
(0x10L) (10000000L) (1e6L) (1.1L) | |
(1e-3L) (4123.381E-10i) | |
(3.) (3.E10) # BUG: .E10 should be part of number | |
# Numbers in some different contexts | |
1L | |
0x40 | |
.234 | |
3. | |
1L + 30 | |
plot(cars, xlim=20) | |
plot(cars, xlim=0x20) | |
foo<-30 | |
my.data.3 <- read() # not a number | |
c(1,2,3) | |
1%%2 | |
"this is a quote that spans | |
multiple lines | |
\" | |
is this still a quote? it should be. | |
# even still! | |
" # now we're done. | |
'same for | |
single quotes #' | |
# keywords | |
NULL, NA, TRUE, FALSE, Inf, NaN, NA_integer_, | |
NA_real_, NA_character_, NA_complex_, function, | |
while, repeat, for, if, in, else, next, break, | |
..., ..1, ..2 | |
# not keywords | |
the quick brown fox jumped over the lazy dogs | |
null na true false inf nan na_integer_ na_real_ | |
na_character_ na_complex_ Function While Repeat | |
For If In Else Next Break .. .... "NULL" `NULL` 'NULL' | |
# operators | |
+, -, *, /, %%, ^, >, >=, <, <=, ==, !=, !, &, |, ~, | |
->, <-, <<-, $, :, :: | |
# infix operator | |
foo %union% bar | |
%"test"% | |
`"test"` | |
""" | |
# Back-to-Julia test | |
function fun(a, b) | |
# hello World | |
return a + b # hi | |
end | |
""" | |
Hello World | |
""" | |
############################################################### | |
# R: little tests | |
############################################################### | |
a = R" a = fun('a', 1.23) " | |
a = R" a = fun('a', 1.23) " | |
a = R""" a = fun('a', "b", 1.23) """ | |
a = R""" a = fun('a', "b", 1.23) """ | |
a = R""" a = fun('a', "b", 1.23) """ | |
############################################################### | |
# JS: big test | |
############################################################### | |
js""" // from: https://highlightjs.org/static/demo/ | |
function $initHighlight(block, cls) { | |
try { | |
if (cls.search(/\bno\-highlight\b/) != -1) | |
return process(block, true, 0x0F) + | |
` class="${cls}"`; | |
} catch (e) { | |
/* handle exception */ | |
} | |
for (var i = 0 / 2; i < classes.length; i++) { | |
if (checkCondition(classes[i]) === undefined) | |
console.log('undefined'); | |
} | |
return ( | |
<div> | |
<web-component>{block}</web-component> | |
</div> | |
) | |
} | |
// other comment | |
export $initHighlight; | |
""" | |
# Back-to-Julia test | |
function fun(a, b) | |
# hello World | |
return a + b # hi | |
end | |
""" | |
Hello World | |
""" | |
############################################################### | |
# JS: little tests | |
############################################################### | |
a = js" a = fun('a', 1.23) " | |
a = js" a = fun('a', 1.23) " | |
a = js""" a = fun('a', "b", 1.23) """ | |
a = js""" a = fun('a', "b", 1.23) """ | |
a = js""" a = fun('a', "b", 1.23) """ | |
############################################################### | |
# Cpp: big test | |
############################################################### | |
cxx""" // from https://highlightjs.org/static/demo/ | |
#include <iostream> | |
int main(int argc, char argv) { | |
/* An annoying "Hello World" example */ | |
for (auto i = 0; i < 0xFFFF; i++) | |
cout << "Hello, World!" << endl; | |
char c = '\n'; | |
unordered_map <string, vector<string> > m; | |
m["key"] = "\\\\"; // this is an error | |
// other comment | |
return -2e3 + 12l; | |
} | |
""" | |
# Back-to-Julia test | |
function fun(a, b) | |
# hello World | |
return a + b # hi | |
end | |
""" | |
Hello World | |
""" | |
############################################################### | |
# Cpp: little tests | |
############################################################### | |
a = cxx" a = fun('a', 1.23) " | |
a = cxx" a = fun('a', 1.23) " | |
a = cxx""" a = fun('a', "b", 1.23) """ | |
a = cxx""" a = fun('a', "b", 1.23) """ | |
a = cxx""" a = fun('a', "b", 1.23) """ | |
############################################################### | |
# Markdown: big test | |
############################################################### | |
md""" | |
<!-- From https://highlightjs.org/static/demo/ --> | |
# hello world | |
you can write text [with links](http://example.com) inline or [link references][1]. | |
* one _thing_ has *em*phasis | |
* two __things__ are **bold** | |
[1]: http://example.com | |
--- | |
hello world | |
=========== | |
<this_is inline="xml"></this_is> | |
> markdown is so cool | |
so are code segments | |
1. one thing (yeah!) | |
2. two thing `i can write code`, and `more` wipee! | |
```py | |
# comment | |
a = fun('a', 1.23) | |
``` | |
""" | |
# Back-to-Julia test | |
function fun(a, b) | |
# hello World | |
return a + b # hi | |
end | |
""" | |
Hello World | |
""" | |
############################################################### | |
# All: inside fun tests | |
############################################################### | |
function fun(a, b) | |
# hello World | |
c = R" $b + 33 + g('abcd') " | |
d = R""" | |
b + 33 + g('abcd') # comment | |
""" | |
c = js" $b + 33 + g('abcd') " | |
d = js""" | |
b + 33 + g('abcd') // comment | |
""" | |
c = cxx" $b + 33 + g('abcd') " | |
d = cxx""" | |
b + 33 + g('abcd') // comment | |
""" | |
c = py" $b + 33 + g('abcd') " | |
d = py""" | |
b + 33 + g('abcd') # comment | |
""" # needs the kludgey out indent, or it gets flagged as a docstring | |
c = md" hello **world** " | |
d = md""" | |
# heading doesn't work if indented | |
hello **world** | |
""" # something's goofy on the trailing triple quotes | |
# hello World | |
return a + b # hi | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment