Spaces:
Running
Running
Download tests/python-highlight.test.mjs from fffiloni/Sand3D-assets-explorer: direct link, hf CLI and curl.
- Browser
- Download file 967 Bytes
-
https://huggingface.co/spaces/fffiloni/Sand3D-assets-explorer/resolve/main/tests/python-highlight.test.mjs
- Command line
-
hf download hf://spaces/fffiloni/Sand3D-assets-explorer/tests/python-highlight.test.mjs
-
curl -L -o python-highlight.test.mjs https://huggingface.co/spaces/fffiloni/Sand3D-assets-explorer/resolve/main/tests/python-highlight.test.mjs
967 Bytes
| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import {JSDOM} from 'jsdom'; | |
| import {highlightPython} from '../src/python-highlight.ts'; | |
| test('Python markup preserves the program and never turns source strings into active HTML',()=>{ | |
| const source='import sand3d as s3d\n# dimensions\ndef make(w=12.5):\n text = """</code><img src=x onerror=alert(1)>\n<script>alert(2)</script>&"""\n return s3d.box("part", w, 3, 4)\n'; | |
| const dom=new JSDOM('<pre><code></code></pre>'),code=dom.window.document.querySelector('code'); | |
| code.innerHTML=highlightPython(source);assert.equal(code.textContent,source); | |
| assert(code.querySelector('.hljs-keyword'));assert(code.querySelector('.hljs-string'));assert(code.querySelector('.hljs-number'));assert(code.querySelector('.hljs-comment')); | |
| assert.equal(code.querySelectorAll('script,img,a,iframe').length,0);assert([...code.querySelectorAll('*')].every(el=>el.tagName==='SPAN')); | |
| dom.window.close(); | |
| }); | |