File tree Expand file tree Collapse file tree 4 files changed +59
-14
lines changed
Expand file tree Collapse file tree 4 files changed +59
-14
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11# Package
22
3- version = " 0.1.3 "
3+ version = " 0.1.4 "
44author = " TelegramXPlus"
55description = " Simple parser for HTML"
66license = " 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"
Original file line number Diff line number Diff line change 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"
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments