Skip to content

Commit d34ad69

Browse files
committed
new tests, rename package
1 parent a9d2ad6 commit d34ad69

11 files changed

+151
-7
lines changed

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Mocha Tests",
11+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
12+
"args": [
13+
"-u",
14+
"tdd",
15+
"--timeout",
16+
"999999",
17+
"--colors",
18+
"${workspaceFolder}/test"
19+
],
20+
"internalConsoleOptions": "openOnSessionStart"
21+
}
22+
]
23+
}

cshtml.js renamed to cshtml-razor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Language: CSHTML
2+
* Language: cshtml-razor
33
* Requires: xml.js, cs.js
44
* Author: Roman Resh <[email protected]>
55
*/
@@ -14,7 +14,7 @@ function hljsDefineCshtmlRazor(hljs) {
1414
returnBegin: true,
1515
end: "</text>",
1616
returnEnd: true,
17-
subLanguage: "cshtml",
17+
subLanguage: "cshtml-razor",
1818
contains: [
1919
{
2020
begin: "[@]{0,1}<text>",
@@ -189,7 +189,7 @@ function hljsDefineCshtmlRazor(hljs) {
189189
variants: BUILT_IN_CODE_BLOCKS_VARIANTS,
190190
returnBegin: true,
191191
returnEnd: true,
192-
subLanguage: "cshtml",
192+
subLanguage: "cshtml-razor",
193193
contains: [
194194
{
195195
variants: BUILT_IN_CODE_BLOCKS_VARIANTS.map(function(v) {
@@ -347,7 +347,7 @@ function hljsDefineCshtmlRazor(hljs) {
347347
begin: "@section[\\s]+[a-zA-Z0-9]+[\\s]*{",
348348
returnBegin: true,
349349
returnEnd: true,
350-
subLanguage: "cshtml",
350+
subLanguage: "cshtml-razor",
351351
end: "}",
352352
contains: [
353353
{

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
"name": "highlightjs-cshtml-razor",
33
"version": "1.0.0",
44
"description": "highlight.js syntax definition for ASP.NET Razor CSHTML language",
5-
"main": "cshtml.js",
5+
"main": "cshtml-razor.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "./node_modules/.bin/mocha --reporter spec"
88
},
99
"repository": {
1010
"type": "git",
1111
"url": "git+https://github.com/highlightjs/highlightjs-cshtml-razor.git"
1212
},
1313
"keywords": [
1414
"cshtml",
15+
"cshtml-razor",
16+
"razor-cshtml",
17+
"razor",
1518
"hljs",
1619
"highlightjs",
1720
"highlight.js",
@@ -25,5 +28,10 @@
2528
"bugs": {
2629
"url": "https://github.com/highlightjs/highlightjs-cshtml-razor/issues"
2730
},
28-
"homepage": "https://github.com/highlightjs/highlightjs-cshtml-razor#readme"
31+
"homepage": "https://github.com/highlightjs/highlightjs-cshtml-razor#readme",
32+
"devDependencies": {
33+
"highlightjs": "^9.10.0",
34+
"mocha": "^5.2.0",
35+
"should": "^13.2.3"
36+
}
2937
}

test/detect.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@model Person
2+
3+
@{
4+
ViewData["Title"] = "Bootstrap Editors";
5+
}
6+
<div class="overview-form">
7+
@if(ViewData["Message"] != null) {
8+
<h3 class="text-success">@ViewData["Message"] </h3>
9+
}
10+
else {
11+
@using(Html.BeginForm(FormMethod.Post)) {
12+
<div class="form-group">
13+
@(Html.DevExpress()
14+
.BootstrapTextBoxFor(m => m.UserName))
15+
</div>
16+
<div class="form-group">
17+
@(Html.DevExpress()
18+
.BootstrapTextBoxFor(m => m.Password)
19+
.Password(true))
20+
</div>
21+
<div class="form-group">
22+
@(Html.DevExpress()
23+
.BootstrapButton("Register")
24+
.Text("Register")
25+
.UseSubmitBehavior(true)
26+
.SettingsBootstrap(settings => settings.RenderOption(BootstrapRenderOption.Primary))
27+
.CssClasses(classes => classes.Control("form-control")))
28+
</div>
29+
}
30+
}
31+
</div>

test/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var should = require('should');
2+
var promisify = require("util").promisify;
3+
let path = require('path');
4+
let hljs = require("highlightjs");
5+
const fs = require("fs");
6+
let hljsDefineCshtmlRazor = require("../cshtml-razor");
7+
8+
const readdir = promisify(fs.readdir),
9+
readFile = promisify(fs.readFile);
10+
11+
describe("CSHTML Razor Tests", () => {
12+
beforeEach(() => {
13+
hljsDefineCshtmlRazor(hljs);
14+
});
15+
it("should generate correct markup", async () => {
16+
var files = await readdir(path.join(__dirname, "markup"));
17+
files = files.filter(f => !f.includes(".expect."));
18+
for(var f of files) {
19+
let fn = path.join(__dirname, "markup", f);
20+
let expectFn = fn.replace(".txt", ".expect.txt");
21+
var code = await readFile(fn, "utf-8");
22+
var exp = await readFile(expectFn, "utf-8");
23+
var actual = hljs.highlight("cshtml-razor", code).value;
24+
actual.trim().should.eql(exp.trim(), f);
25+
}
26+
});
27+
it("should be detected correctly", async () => {
28+
var code = await readFile(path.join(__dirname, "detect.txt"), "utf-8");
29+
var actual = hljs.highlightAuto(code).language;
30+
actual.should.eql("cshtml-razor");
31+
});
32+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<span class="xml">before
2+
</span><span class="cs"></span><span class="hljs-built_in">@{</span><span class="cs">
3+
<span class="hljs-keyword">var</span> inCSharp = <span class="hljs-literal">true</span>;
4+
</span><span class="cshtml-razor"><span class="xml"></span></span><span class="hljs-built_in">&lt;text&gt;</span><span class="cshtml-razor"><span class="xml">xml</span></span><span class="hljs-built_in">&lt;/text&gt;</span><span class="cs">
5+
</span><span class="hljs-built_in">}</span><span class="xml">
6+
after
7+
</span><span class="cs"></span><span class="hljs-built_in">@{</span><span class="cs">
8+
<span class="hljs-keyword">var</span> inCSharp = <span class="hljs-literal">true</span>;
9+
</span><span class="cshtml-razor"><span class="xml"></span></span><span class="hljs-built_in">&lt;text&gt;</span><span class="cshtml-razor"><span class="xml">xml</span></span><span class="hljs-built_in">&lt;/text&gt;</span><span class="cs">
10+
</span><span class="hljs-built_in">}</span><span class="xml"></span>

test/markup/code-block-multiline.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
before
2+
@{
3+
var inCSharp = true;
4+
<text>xml</text>
5+
}
6+
after
7+
@{
8+
var inCSharp = true;
9+
<text>xml</text>
10+
}

test/markup/if-else-block.expect.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<span class="xml">before
2+
</span><span class="cshtml-razor"><span class="xml"></span></span><span class="hljs-built_in">@</span><span class="cs"><span class="hljs-keyword">if</span>(<span class="hljs-literal">true</span>) </span><span class="hljs-built_in">{</span><span class="cshtml-razor"><span class="xml">
3+
block
4+
</span></span><span class="hljs-built_in">}</span><span class="cs"> <span class="hljs-keyword">else</span> </span><span class="hljs-built_in">{</span><span class="cshtml-razor"><span class="xml">
5+
block
6+
</span></span><span class="hljs-built_in">}</span><span class="xml">
7+
after</span>

test/markup/if-else-block.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
before
2+
@if(true) {
3+
block
4+
} else {
5+
block
6+
}
7+
after

test/markup/inline.expect.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<span class="xml">Hello </span><span class="cs"></span><span class="hljs-built_in">@</span><span class="cs">owner</span><span class="xml"> from html
2+
Hello </span><span class="cs"></span><span class="hljs-built_in">@</span><span class="cs">owner[<span class="hljs-string">"test"</span>]</span><span class="xml"> from html
3+
Hello </span><span class="cs"></span><span class="hljs-built_in">@</span><span class="cs">owner.test</span><span class="xml"> from html
4+
Hello </span><span class="cs"></span><span class="hljs-built_in">@</span><span class="cs">owner</span><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span>from html<span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span>
5+
Hello </span><span class="cs"></span><span class="hljs-built_in">@</span><span class="cs">owner</span><span class="xml">
6+
from html
7+
8+
@@escapedat</span>

0 commit comments

Comments
 (0)