Skip to content

Commit

Permalink
add workflows and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TelegramXPlus committed Sep 9, 2024
1 parent 5c349cd commit 71118d6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
nim-versions: ['1.0.0', '1.6.6', 'stable']
steps:
- uses: actions/checkout@v4
- uses: jiro4989/setup-nim-action@v2
with:
nim-version: ${{ matrix.nim-versions }}
- run: nimble test -y
8 changes: 6 additions & 2 deletions beautifulparser.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.1.3"
version = "0.1.4"
author = "TelegramXPlus"
description = "Simple parser for HTML"
license = "MIT"
Expand All @@ -9,4 +9,8 @@ srcDir = "src"

# Dependencies

requires "nim >= 1.6.6"
requires "nim >= 1.0.0"


task test, "Run tests":
exec "nim c -r tests/test.nim"
36 changes: 36 additions & 0 deletions tests/test.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
import htmlparser
import strtabs
import beautifulparser


suite "beautifulparser":
let htmlString = """
<html>
<head>
<title>Test</title>
</head>
<body>
<a href="url">Link</a>
<p class="p">Paragraph</p>
<p class="p">Another paragraph</p>
</body>
</html>
"""
let html = parseHtml(htmlString)

test "find title":
let title = html.findNode("title")
check title.isSome
check title.get().innerText == "Test"

test "find link":
let link = html.findNode("a")
check link.isSome
check link.get().innerText == "Link"
check link.get().attrs.getOrDefault("href", "") == "url"

test "find paragraphs":
let paragraphs = html.findAllNodes("p", {"class": "p"})
check paragraphs.len == 2
check paragraphs[0].innerText == "Paragraph"
12 changes: 0 additions & 12 deletions tests/test1.nim

This file was deleted.

0 comments on commit 71118d6

Please sign in to comment.