Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
feat: definition list item
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed May 14, 2016
1 parent 237d58f commit b34ce98
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
7 changes: 7 additions & 0 deletions grammars/language-asciidoc.cson
Expand Up @@ -274,6 +274,13 @@ repository:
"1":
name: "markup.list.bullet.asciidoc"
}
{
name: "markup.heading.list.asciidoc"
match: "^\\p{Blank}*(.*?\\S)(:{2,4}|;;)($|\\p{Blank}+)"
captures:
"2":
name: "markup.list.bullet.asciidoc"
}
]
section:
patterns: [
Expand Down
15 changes: 15 additions & 0 deletions grammars/repositories/partials/list-grammar.cson
Expand Up @@ -44,4 +44,19 @@ patterns: [
match: '^\\p{Blank}*(\\.{1,5}|\\d+\\.|[a-zA-Z]\\.|[IVXivx]+\\))(?=\\p{Blank})'
captures:
1: name: 'markup.list.bullet.asciidoc'

,
# Matches a definition list item.
#
# Examples
#
# foo::
# foo:::
# foo::::
# foo;;
#
name: 'markup.heading.list.asciidoc'
match: '^\\p{Blank}*(.*?\\S)(:{2,4}|;;)($|\\p{Blank}+)'
captures:
2: name: 'markup.list.bullet.asciidoc'
]
88 changes: 88 additions & 0 deletions spec/partials/list-labeled-grammar-spec.coffee
@@ -0,0 +1,88 @@
describe 'Labeled list', ->
grammar = null

beforeEach ->
waitsForPromise ->
atom.packages.activatePackage 'language-asciidoc'

runs ->
grammar = atom.grammars.grammarForScopeName 'source.asciidoc'

it 'parses the grammar', ->
expect(grammar).toBeDefined()
expect(grammar.scopeName).toBe 'source.asciidoc'

describe 'Should tokenizes labeled list when', ->

it 'line ending with ::', ->
{tokens} = grammar.tokenizeLine 'foobar::'
expect(tokens).toHaveLength 2
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: '::', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']

it 'line ending with :::', ->
{tokens} = grammar.tokenizeLine 'foobar:::'
expect(tokens).toHaveLength 2
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: ':::', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']

it 'line ending with ::::', ->
{tokens} = grammar.tokenizeLine 'foobar::::'
expect(tokens).toHaveLength 2
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: '::::', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']

it 'line ending with ;;', ->
{tokens} = grammar.tokenizeLine 'foobar;;'
expect(tokens).toHaveLength 2
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: ';;', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']

it 'contains :: following by text', ->
{tokens} = grammar.tokenizeLine 'foobar:: foobar'
expect(tokens).toHaveLength 4
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: '::', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']
expect(tokens[2]).toEqualJson value: ' ', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[3]).toEqualJson value: 'foobar', scopes: ['source.asciidoc']

it 'contains ::: following by text', ->
{tokens} = grammar.tokenizeLine 'foobar::: foobar'
expect(tokens).toHaveLength 4
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: ':::', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']
expect(tokens[2]).toEqualJson value: ' ', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[3]).toEqualJson value: 'foobar', scopes: ['source.asciidoc']

it 'contains :::: following by textcontains :: following by text', ->
{tokens} = grammar.tokenizeLine 'foobar:::: foobar'
expect(tokens).toHaveLength 4
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: '::::', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']
expect(tokens[2]).toEqualJson value: ' ', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[3]).toEqualJson value: 'foobar', scopes: ['source.asciidoc']

it 'contains ;; following by text', ->
{tokens} = grammar.tokenizeLine 'foobar;; foobar'
expect(tokens).toHaveLength 4
expect(tokens[0]).toEqualJson value: 'foobar', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[1]).toEqualJson value: ';;', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc', 'markup.list.bullet.asciidoc']
expect(tokens[2]).toEqualJson value: ' ', scopes: ['source.asciidoc', 'markup.heading.list.asciidoc']
expect(tokens[3]).toEqualJson value: 'foobar', scopes: ['source.asciidoc']

describe 'Should not tokenize when', ->

it 'title ending with space', ->
{tokens} = grammar.tokenizeLine 'foobar ::'
expect(tokens).toHaveLength 1
expect(tokens[0]).toEqualJson value: 'foobar ::', scopes: ['source.asciidoc']

it 'contains only one :', ->
{tokens} = grammar.tokenizeLine 'foobar:'
expect(tokens).toHaveLength 1
expect(tokens[0]).toEqualJson value: 'foobar:', scopes: ['source.asciidoc']

it 'following by test without space', ->
{tokens} = grammar.tokenizeLine 'foobar:foobar'
expect(tokens).toHaveLength 1
expect(tokens[0]).toEqualJson value: 'foobar:foobar', scopes: ['source.asciidoc']

0 comments on commit b34ce98

Please sign in to comment.