Skip to content

Commit

Permalink
Merge pull request #10 from keplersj/jest
Browse files Browse the repository at this point in the history
Transition to Jest, Increase Languages Tested, and Fix Bug with Sub-Languages
  • Loading branch information
felixfbecker committed Nov 25, 2017
2 parents 2d6d026 + de2b227 commit d798e0f
Show file tree
Hide file tree
Showing 193 changed files with 11,368 additions and 105 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -6,6 +6,7 @@ node_js:
env:
global:
- FORCE_COLOR=1
- OUTPUT_CODE_SAMPLES=1

cache:
directories:
Expand All @@ -17,10 +18,9 @@ install:
script:
- npm run lint
- npm run build
- npm run cover
- npm run test

after_success:
- nyc report --reporter=json
- bash <(curl -s https://codecov.io/bash)

jobs:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -76,8 +76,8 @@ The theme is combined with the [default theme](http://cli-highlight.surge.sh/glo
The default theme is still not colored a lot or optimized for many languages, PRs welcome!

## Supported Languages
In theory, [all languages of highlight.js](https://highlightjs.org/static/demo/) are supported - I just did not adapt
the default theme and wrote tests for all languages yet. My primary use case was SQL so that is supported well.
[All languages of highlight.js](https://highlightjs.org/static/demo/) are supported.
Check a [CI build](https://travis-ci.org/felixfbecker/cli-highlight) for examples of all the different languages and their highlighting.

## Contributing
The module is written in TypeScript and can be compiled with `npm run build`.
Expand Down
31 changes: 19 additions & 12 deletions package.json
Expand Up @@ -17,8 +17,7 @@
"node": ">=4.0.0"
},
"scripts": {
"test": "mocha dist/test",
"cover": "nyc --all mocha dist/test",
"test": "jest",
"lint": "npm run tslint && npm run prettier",
"tslint": "tslint -c tslint.json -p tsconfig.json",
"prettier": "prettier --write --list-different '**/{*.ts,*.json,.prettierrc}'",
Expand All @@ -28,13 +27,21 @@
"semantic-release": "semantic-release",
"commitmsg": "validate-commit-msg"
},
"nyc": {
"include": [
"dist/**/*.js"
],
"exclude": [
"dist/test/**/*.js",
"dist/cli.js"
"jest": {
"collectCoverage": true,
"mapCoverage": true,
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/test/.*|/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": ["/node_modules/", "/src/test/__fixtures__/"],
"coverageReporters": ["json", "text"],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
},
"config": {
Expand Down Expand Up @@ -74,16 +81,16 @@
"@sourcegraph/prettierrc": "^2.0.0",
"@sourcegraph/tslint-config": "^9.0.3",
"@types/highlight.js": "^9.12.1",
"@types/mocha": "^2.2.44",
"@types/jest": "^21.1.8",
"@types/mz": "0.0.32",
"@types/node": "^8.0.53",
"@types/yargs": "^8.0.2",
"cz-conventional-changelog": "^2.1.0",
"husky": "^0.14.3",
"mocha": "^4.0.1",
"nyc": "^11.3.0",
"jest": "^21.2.1",
"prettier": "1.8.2",
"semantic-release": "^10.0.0",
"ts-jest": "^21.2.3",
"tslint": "^5.8.0",
"typedoc": "^0.9.0",
"typescript": "^2.6.1",
Expand Down
16 changes: 11 additions & 5 deletions src/index.ts
Expand Up @@ -7,11 +7,17 @@ function colorizeNode(node: parse5.AST.HtmlParser2.Node, theme: Theme = {}): str
return (node as parse5.AST.HtmlParser2.TextNode).data
} else if (node.type === 'tag') {
const hljsClass = /hljs-(\w+)/.exec((node as parse5.AST.HtmlParser2.Element).attribs.class)
const token = hljsClass[1]
const nodeData = (node as parse5.AST.HtmlParser2.Element).childNodes
.map(node => colorizeNode(node, theme))
.join('')
return ((theme as any)[token] || (DEFAULT_THEME as any)[token] || plain)(nodeData)
if (hljsClass) {
const token = hljsClass[1]
const nodeData = (node as parse5.AST.HtmlParser2.Element).childNodes
.map(node => colorizeNode(node, theme))
.join('')
return ((theme as any)[token] || (DEFAULT_THEME as any)[token] || plain)(nodeData)
}

// Return the data itself when the class name isn't prefixed with a highlight.js token prefix.
// This is common in instances of sublanguages (JSX, Markdown Code Blocks, etc.)
return (node as parse5.AST.HtmlParser2.Element).childNodes.map(node => colorizeNode(node, theme)).join('')
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/test/__fixtures__/1C Enterprise.bsl
@@ -0,0 +1,30 @@
#ЗагрузитьИзФайла ext_module.txt // директива 7.7
#Если Клиент ИЛИ НаКлиенте Тогда // инструкции препроцессора
&НаКлиентеНаСервереБезКонтекста // директивы компиляции
Функция ТолстыйКлиентОбычноеПриложение(Знач Параметр1 = Неопределено, // комментарий
Параметр2 = "", ПараметрN = 123.45, ПарамNN) Экспорт // еще комментарий
Попытка
Результат_Булевы_Значения = Новый Структура("П1, П2", Истина, Ложь, NULL, Неопределено);
Перейти ~МеткаGOTO; // комментарий
РезультатТаблицаДат = Новый ТаблицаЗначений;
РезультатТаблицаДат.Колонки.Добавить("Колонка1",
Новый ОписаниеТипов("Дата", , ,
Новый КвалификаторыДаты(ЧастиДаты.ДатаВремя));
НС = РезультатТаблицаДат.Добавить(); НС["Колонка1"] = '20170101120000');
Исключение
ОписаниеОшибки = ОписаниеОшибки(); // встроенная функция
Масс = Новый Массив; // встроенный тип
Для Каждого Значение Из Масс Цикл
Сообщить(Значение + Символы.ПС + "
|продолжение строки"); // продолжение многострочной строки
Продолжить; Прервать;
КонецЦикла;
СправочникСсылка = Справочники.Языки.НайтиПоНаименованию("ru"); // встроенные типы
СправочникОбъект = СправочникСсылка.ПолучитьОбъект();
ПеречислениеСсылка = Перечисления.ВидыМодификацииДанных.Изменен;
ВызватьИсключение ОписаниеОшибки;
КонецПопытки;
~МеткаGOTO: // еще комментарий
ВД = ВидДвиженияБухгалтерии.Дебет;
КонецФункции // ТолстыйКлиентОбычноеПриложение()
#КонецЕсли
22 changes: 22 additions & 0 deletions src/test/__fixtures__/ABNF.abnf
@@ -0,0 +1,22 @@
; line comment

ruleset = [optional] *(group1 / group2 / SP) CRLF ; trailing comment

group1 = alt1
group1 =/ alt2

alt1 = %x41-4D / %d78-90

alt2 = %b00100001

group2 = *1DIGIT / 2*HEXDIG / 3*4OCTET

optional = hex-codes
/ literal
/ sensitive
/ insensitive

hex-codes = %x68.65.6C.6C.6F
literal = "string literal"
sensitive = %s"case-sensitive string"
insensitive = %i"case-insensitive string"
36 changes: 36 additions & 0 deletions src/test/__fixtures__/ARM Assembly.txt
@@ -0,0 +1,36 @@
.text

.global connect
connect:
mov r3, #2 ; s->sin_family = AF_INET
strh r3, [sp]
ldr r3, =server_port ; s->sin_port = server_port
ldr r3, [r3]
strh r3, [sp, #2]
ldr r3, =server_addr ; s->sin_addr = server_addr
ldr r3, [r3]
str r3, [sp, #4]
mov r3, #0 ; bzero(&s->sin_zero)
str r3, [sp, #8]
str r3, [sp, #12]
mov r1, sp ; const struct sockaddr *addr = sp

ldr r7, =connect_call
ldr r7, [r7]
swi #0

add sp, sp, #16
pop {r0} ; pop sockfd

pop {r7}
pop {fp, ip, lr}
mov sp, ip
bx lr

.data
socket_call: .long 281
connect_call: .long 283

/* all addresses are network byte-order (big-endian) */
server_addr: .long 0x0100007f ; localhost
server_port: .hword 0x0b1a
19 changes: 19 additions & 0 deletions src/test/__fixtures__/AVR Assembly.txt
@@ -0,0 +1,19 @@
;* Title: Block Copy Routines
;* Version: 1.1

.include "8515def.inc"

rjmp RESET ;reset handle

.def flashsize=r16 ;size of block to be copied

flash2ram:
lpm ;get constant
st Y+,r0 ;store in SRAM and increment Y-pointer
adiw ZL,1 ;increment Z-pointer
dec flashsize
brne flash2ram ;if not end of table, loop more
ret

.def ramtemp =r1 ;temporary storage register
.def ramsize =r16 ;size of block to be copied
1 change: 1 addition & 0 deletions src/test/__fixtures__/Access Log.log
@@ -0,0 +1 @@
20.164.151.111 - - [20/Aug/2015:22:20:18 -0400] "GET /mywebpage/index.php HTTP/1.1" 403 772 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1"
24 changes: 24 additions & 0 deletions src/test/__fixtures__/ActionScript.as3
@@ -0,0 +1,24 @@
package org.example.dummy {
import org.dummy.*;

/*define package inline interface*/
public interface IFooBarzable {
public function foo(... pairs):Array;
}

public class FooBar implements IFooBarzable {
static private var cnt:uint = 0;
private var bar:String;

//constructor
public function TestBar(bar:String):void {
bar = bar;
++cnt;
}

public function foo(... pairs):Array {
pairs.push(bar);
return pairs;
}
}
}
17 changes: 17 additions & 0 deletions src/test/__fixtures__/Ada.txt
@@ -0,0 +1,17 @@
package body Sqlite.Simple is

Foo : int := int'Size;
Bar : int := long'Size;

Error_Message_C : chars_ptr := Sqlite_Errstr (Error);
Error_Message : String := Null_Ignore_Value (Error_Message_C);
begin

Named : for Index in Foo..Bar loop
Put ("Hi[]{}");
end loop Named;

Foo := Bar;
end Message;

end Sqlite.Simple;
19 changes: 19 additions & 0 deletions src/test/__fixtures__/ApacheConf.txt
@@ -0,0 +1,19 @@
# rewrite`s rules for wordpress pretty url
LoadModule rewrite_module modules/mod_rewrite.so
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [NC,L]

ExpiresActive On
ExpiresByType application/x-javascript "access plus 1 days"

Order Deny,Allow
Allow from All

<Location /maps/>
RewriteMap map txt:map.txt
RewriteMap lower int:tolower
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]
RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L]
</Location>
14 changes: 14 additions & 0 deletions src/test/__fixtures__/AppleScript.txt
@@ -0,0 +1,14 @@
repeat 5 times
if foo is greater than bar then
display dialog "Hello there"
else
beep
end if
end repeat

(* comment (*nested comment*) *)
on do_something(s, y)
return {s + pi, y mod 4}
end do_something

do shell script "/bin/echo 'hello'"
24 changes: 24 additions & 0 deletions src/test/__fixtures__/Arduino.txt
@@ -0,0 +1,24 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
65 changes: 65 additions & 0 deletions src/test/__fixtures__/AsciiDoc.txt
@@ -0,0 +1,65 @@
Hello, World!
============
Author Name, <author@domain.foo>

you can write text http://example.com[with links], optionally
using an explicit link:http://example.com[link prefix].

* single quotes around a phrase place 'emphasis'
** alternatively, you can put underlines around a phrase to add _emphasis_
* astericks around a phrase make the text *bold*
* pluses around a phrase make it +monospaced+
* `smart' quotes using a leading backtick and trailing single quote
** use two of each for double ``smart'' quotes

- escape characters are supported
- you can escape a quote inside emphasized text like 'here\'s johnny!'

term:: definition
another term:: another definition

// this is just a comment

Let's make a break.

'''

////
we'll be right with you

after this brief interruption.
////

== We're back!

Want to see a image::images/tiger.png[Tiger]?

.Nested highlighting
++++
<this_is inline="xml"></this_is>
++++

____
asciidoc is so powerful.
____

another quote:

[quote, Sir Arthur Conan Doyle, The Adventures of Sherlock Holmes]
____
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
____

Getting Literal
---------------

want to get literal? prefix a line with a space.

....
I'll join that party, too.
....

. one thing (yeah!)
. two thing `i can write code`, and `more` wipee!

NOTE: AsciiDoc is quite cool, you should try it.

0 comments on commit d798e0f

Please sign in to comment.