Skip to content

Commit f0b1ced

Browse files
committed
Add a test for syntax highlighting
1 parent 196242f commit f0b1ced

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
*** Settings ***
2+
Suite Setup Setup Suite For Screenshots syntax_highlighting
3+
Test Setup Setup Highlighting Test
4+
Test Teardown Clean Up After Working With File Syntax highlighting.ipynb
5+
Force Tags feature:syntax_highlighting
6+
Resource ../Keywords.robot
7+
8+
*** Test Cases ***
9+
Syntax Highlighting Mode Stays Normal In Normal Cells
10+
${mode} = Get Mode Of A Cell 1
11+
should be equal ${mode['name']} ipython
12+
13+
Syntax Highlighting Mode Changes In Cells Dominated By Foreign Documents
14+
${mode} = Get Mode Of A Cell 2
15+
should be equal ${mode['name']} markdown
16+
${mode} = Get Mode Of A Cell 3
17+
should be equal ${mode['name']} xml
18+
${mode} = Get Mode Of A Cell 4
19+
should be equal ${mode['name']} javascript
20+
21+
Highlighing Mode Works For Multiple Documents
22+
${mode} = Get Mode Of A Cell 4
23+
should be equal ${mode['name']} javascript
24+
${mode} = Get Mode Of A Cell 6
25+
should be equal ${mode['name']} javascript
26+
27+
*** Keywords ***
28+
Get Mode Of A Cell
29+
[Arguments] ${cell_nr}
30+
Click Element css:.jp-Cell:nth-child(${cell_nr})
31+
Wait Until Page Contains Element css:.jp-Cell:nth-child(${cell_nr}) .CodeMirror-focused
32+
${mode} = Execute JavaScript return document.querySelector('.jp-Cell:nth-child(${cell_nr}) .CodeMirror').CodeMirror.getMode()
33+
[Return] ${mode}
34+
35+
Setup Highlighting Test
36+
Setup Notebook Python Syntax highlighting.ipynb
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"variable = 1\n",
10+
"\n",
11+
"def function():\n",
12+
" return\n",
13+
"\n",
14+
"# note print is highlighted in Python but function is not\n",
15+
"print(variable, function)"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"%%markdown\n",
25+
"# header\n",
26+
"**bold**, *italic*\n",
27+
"\n",
28+
"### Heading with wrong level"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"%%html\n",
38+
"<html style=\"color: green\">\n",
39+
" <!-- this is a comment -->\n",
40+
" <head>\n",
41+
" <title>HTML Example</title>\n",
42+
" </head>\n",
43+
" <body>\n",
44+
" The indentation tries to be <em>somewhat &quot;do what\n",
45+
" I mean&quot;</em>... but might not match your style.\n",
46+
" </body>\n",
47+
"</html>"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"%%javascript\n",
57+
"// \"print\" is NOT highlighted in javascript, while \"function\" is\n",
58+
"function add_together(a, b) {\n",
59+
" return a + b\n",
60+
"}\n",
61+
"\n",
62+
"print('A')"
63+
]
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"metadata": {},
68+
"source": [
69+
"It should work for the same language of virtual document with multiple occurrences:"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"%%javascript \n",
79+
"function add_together(a, b) {\n",
80+
" return a + b\n",
81+
"}\n",
82+
"\n",
83+
"print('A')"
84+
]
85+
}
86+
],
87+
"metadata": {
88+
"kernelspec": {
89+
"display_name": "Python 3",
90+
"language": "python",
91+
"name": "python3"
92+
},
93+
"language_info": {
94+
"codemirror_mode": {
95+
"name": "ipython",
96+
"version": 3
97+
},
98+
"file_extension": ".py",
99+
"mimetype": "text/x-python",
100+
"name": "python",
101+
"nbconvert_exporter": "python",
102+
"pygments_lexer": "ipython3",
103+
"version": "3.7.5"
104+
}
105+
},
106+
"nbformat": 4,
107+
"nbformat_minor": 4
108+
}

0 commit comments

Comments
 (0)