Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

180 merge qi into blade #181

Merged
merged 6 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions apps/nyssa/.blade/libs/highlight.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
var blade_keywords = '|'.join([
'as', 'assert', 'break', 'catch', 'class', 'continue',
'def', 'default', 'die', 'do', 'echo', 'else', 'finally', 'for',
'if', 'import', 'in', 'iter', 'return', 'static', 'try',
'using', 'var', 'when', 'while',
])

var constant_keywords = '|'.join([
'nil', 'parent', 'self', 'true', 'false', 'and', 'or'
])

var _quote_re = '/((\'(?:[^\'\\\\]|\\.)*\')|("(?:[^"\\\\]|\\.)*"))/'

def highlight_blade(text) {
text = text.
# operators
replace('/([+\-*=/%!<>@]|\.\.)/', '<_o>$1</_o>').
replace('/\\b(and|or)\\b/', '<_o>$1</_o>').
# quotes
replace(_quote_re, '<_q>$1</_q>').
# constant keywords
replace('/\\b(${constant_keywords})\\b/', '<_c>$1</_c>').

# numbers
replace('/(([0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?)|(0x[0-9a-fA-F]+)|(0c[0-7][0-7]*)|(0b[01][01]*)|([0-9]+))/', '<_n>$1</_n>').

# functions
# property/method call and access
replace('/(?<=\.)[ ]*([a-zA-Z_][a-zA-Z0-9_]*)[ ]*(?=[(])/', '<_m>$1</_m>').
# definition and call
replace('/(?<!\.)([a-zA-Z_][a-zA-Z0-9_]*)[ ]*(?=[(])/', '<_f>$1</_f>').

# keywords
replace('/\\b(${blade_keywords})\\b/', '<_k>$1</_k>').
# comments
replace('/(#[^\\n]*|\/(?!\\\\)\*[\s\S]*?\*(?!\\\\)\/)/', '<_w>$1</_w>')

# clean up comments
var comments = text.matches('/<_w>(.*?)<\/_w>/')
if comments {
for comment in comments[1] {
text = text.replace(comment, comment.replace('/<\/?_([^>]+)>/', ''), false)
}
}

# clean up quotes
var quotes = text.matches('/<_q>(.*?)<\/_q>/')
if quotes {
for quote in quotes[1] {
text = text.replace(
quote,
quote.replace('/<\/?_([^>]+)>/', '').
# interpolation
replace('/(\\$\{[^}]+\})/', '<_i>$1</_i>'),
false
)
}
}

# expand styles.
return text.replace('/<_q>(.*?)<\/_q>/', '<span style="color:#690">$1</span>').
replace('/<_i>(.*?)<\/_i>/', '<span style="color:#00bcd4">$1</span>').
replace('/<_c>(.*?)<\/_c>/', '<span style="color:#ff9800">$1</span>').
replace('/<_m>(.*?)<\/_m>/', '<span style="color:#ff5722;font-style:italic">$1</span>').
replace('/<_f>(.*?)<\/_f>/', '<span style="color:#ff5722">$1</span>').
replace('/<_k>(.*?)<\/_k>/', '<span style="color:#2196F3">$1</span>').
replace('/<_w>(.*?)<\/_w>/', '<span style="color:slategray">$1</span>').
replace('/<_o>(.*?)<\/_o>/', '<span style="color:#9a6e3a">$1</span>').
replace('/<_n>(.*?)<\/_n>/', '<span style="color:#905">$1</span>')
}

def highlight_html5(text, lang) {
var tags = text.matches('/<([^>]+)>/')
if tags {
iter var i = 0; i < tags[0].length(); i++ {
var content = tags[1][i].replace('/([a-zA-Z_\-0-9]+)(?=[=])/', '<^a>$1</^a>').
replace(_quote_re, '<^v>$1</^v>')
text = text.replace(tags[0][i], '<span style="color:#2196f3">&lt;${content}&gt;</span>', false)
}
}

var result = text.replace('/<\^a>(.*?)<\/\^a>/', '<span style="color:#9a6e3a">$1</span>').
replace('/<\^v>(.*?)<\/\^v>/', '<span style="color:#690">$1</span>')

if lang == 'wire' {
result = result.replace('/(\{\{.+?\}\})/', '<span style="color:#ff9800">$1</span>')
}

return result
}

def highlight(text, lang) {
if lang == 'blade' {
return highlight_blade(text)
} else if lang == 'html' or lang == 'html5' or lang == 'wire' {
return highlight_html5(text, lang)
}
return text
}

2 changes: 2 additions & 0 deletions apps/nyssa/.blade/libs/qi/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.b linguist-detectable
*.b linguist-language=Blade
18 changes: 18 additions & 0 deletions apps/nyssa/.blade/libs/qi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# blade packages directory and files
.blade/
*.nyp

# popular editors
.vscode/
.idea/
.vs/

# c object files (for C extensions)
*.o
*.ko
*.obj
*.elf

# log files
*.log
/qi
64 changes: 64 additions & 0 deletions apps/nyssa/.blade/libs/qi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Qi

A testing framework for Blade programming language.

### Package Information

- **Name:** qi
- **Version:** 1.0.0
- **Homepage:** https://github.com/mcfriend99/qi.git
- **Tags:** test, blade, testing, tdd, test-driven
- **Author:** Richard Ore <[email protected]>
- **License:** MIT
- **Requires:** Blade v0.0.86+

### Getting started

Qi is a Nyssa package that ships along with it and is designed to run tests are out the directory `tests` and for this reason, all tests files must reside inside the `tests` directory.

### Writing a simple test

Let's write a test for a hypothetical function that returns the product of two numbers. First, we'll create a file `prod.b` that contains the following code:

```py
def prod(x, y) {
return x * y
}
```

Now, let's create a test for it by creating a file `prod.test.b` in the `tests` directory and add the following code to it.

```py
import ..prod

describe('Product test suite', @() {
it('should return 6 for 2 and 3', @() {
expect(prod(2, 3)).to_be(6)
})
})
```

Now let's run the test. If you have installed Qi using `nyssa` (which is recommended), then you can run the following command at the root directory (the directory that contains the `tests` folder).

```
nyssa test
```

You should get an output similar to this:

```
PASS tests/prod.test.b
Product test suite
✔ should return 6 for 2 and 3 (1.09ms)
✔ expect "6" to be "6"

Test suites: 1 passed, 0 failed, 1 total
Tests: 1 passed, 0 failed, 1 total
Assertions: 1 passed, 0 failed, 1 total
Time: 1.092ms
Ran all test suites.
```

**You have successfully created your first Qi test!**

Read more documentation at: [mcfriend99.github.io/qi](https://mcfriend99.github.io/qi/)
10 changes: 10 additions & 0 deletions apps/nyssa/.blade/libs/qi/app/index.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import .lib { * }
import reflect

reflect.set_global(describe)
reflect.set_global(it)
reflect.set_global(expect)
reflect.set_global(after_each)
reflect.set_global(before_each)
reflect.set_global(after_all)
reflect.set_global(before_all)
Loading