Skip to content

Commit 71118d6

Browse files
committed
add workflows and tests
1 parent 5c349cd commit 71118d6

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
nim-versions: ['1.0.0', '1.6.6', 'stable']
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: jiro4989/setup-nim-action@v2
15+
with:
16+
nim-version: ${{ matrix.nim-versions }}
17+
- run: nimble test -y

beautifulparser.nimble

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.1.3"
3+
version = "0.1.4"
44
author = "TelegramXPlus"
55
description = "Simple parser for HTML"
66
license = "MIT"
@@ -9,4 +9,8 @@ srcDir = "src"
99

1010
# Dependencies
1111

12-
requires "nim >= 1.6.6"
12+
requires "nim >= 1.0.0"
13+
14+
15+
task test, "Run tests":
16+
exec "nim c -r tests/test.nim"

tests/test.nim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import unittest
2+
import htmlparser
3+
import strtabs
4+
import beautifulparser
5+
6+
7+
suite "beautifulparser":
8+
let htmlString = """
9+
<html>
10+
<head>
11+
<title>Test</title>
12+
</head>
13+
<body>
14+
<a href="url">Link</a>
15+
<p class="p">Paragraph</p>
16+
<p class="p">Another paragraph</p>
17+
</body>
18+
</html>
19+
"""
20+
let html = parseHtml(htmlString)
21+
22+
test "find title":
23+
let title = html.findNode("title")
24+
check title.isSome
25+
check title.get().innerText == "Test"
26+
27+
test "find link":
28+
let link = html.findNode("a")
29+
check link.isSome
30+
check link.get().innerText == "Link"
31+
check link.get().attrs.getOrDefault("href", "") == "url"
32+
33+
test "find paragraphs":
34+
let paragraphs = html.findAllNodes("p", {"class": "p"})
35+
check paragraphs.len == 2
36+
check paragraphs[0].innerText == "Paragraph"

tests/test1.nim

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)