-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from vixalien/tests
Add tests
- Loading branch information
Showing
21 changed files
with
1,043 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Meson Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Install Dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install meson libglib2.0-dev | ||
- name: Create Build Environment | ||
run: meson setup ${{github.workspace}}/build | ||
|
||
- name: Build | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
run: ninja | ||
|
||
- name: Stylecheck | ||
run: deno fmt --check | ||
|
||
- name: Lint | ||
run: deno lint | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build | ||
shell: bash | ||
run: meson test --suite deno-gi --print-errorlogs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.vscode/ | ||
|
||
deno.json | ||
deno.jsonc | ||
deno.lock | ||
/subprojects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"unstable": ["ffi"], | ||
"lock": false, | ||
"tasks": { | ||
"test": "deno test --unstable-ffi --allow-ffi --allow-read test/unit/**/*" | ||
}, | ||
"imports": { | ||
"https://github.com/ahgilak/deno_gi/raw/main/mod.ts": "./mod.ts" | ||
}, | ||
"exclude": ["subprojects", "build"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
project( | ||
'deno-gi', | ||
'c', | ||
version: 'master', | ||
) | ||
|
||
gnome = import('gnome') | ||
fs = import('fs') | ||
|
||
deno = find_program('deno', required: true) | ||
|
||
subdir('tests') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { GITypeTag } from "https://raw.githubusercontent.com/ahgilak/deno_gi/main/src/bindings/enums.js"; | ||
|
||
export const NumberRanges = { | ||
[GITypeTag.INT8]: [-128, 127], | ||
[GITypeTag.INT16]: [-32_768, 32_767], | ||
[GITypeTag.INT32]: [-2_147_483_648, 2_147_483_647], | ||
[GITypeTag.INT64]: [-9_223_372_036_854_775_808n, 9_223_372_036_854_775_807n], | ||
[GITypeTag.UINT8]: [0, 255], | ||
[GITypeTag.UINT16]: [0, 65_535], | ||
[GITypeTag.UINT32]: [0, 4_294_967_295], | ||
[GITypeTag.UINT64]: [0, 18_446_744_073_709_551_615n], | ||
// TODO: not sure about these, will probably not be precise | ||
[GITypeTag.FLOAT]: [-3.4e38, 3.4e38], | ||
[GITypeTag.DOUBLE]: [-1.8e308, 1.8e308], | ||
// not sure | ||
[GITypeTag.GTYPE]: [0, 18_446_744_073_709_551_615n], | ||
}; | ||
|
||
export function ensure_number_range( | ||
type: number, | ||
value: number | bigint, | ||
): void { | ||
const range = NumberRanges[type]; | ||
if (!range) return; | ||
|
||
// check if the number is in the given range | ||
const [min, max] = range; | ||
if (value >= min && value <= max) return; | ||
|
||
// doubles & floats accept Infinity and NaN | ||
if (type === GITypeTag.DOUBLE || type === GITypeTag.FLOAT) { | ||
if ([Infinity, -Infinity, NaN].includes(value as number)) return; | ||
} | ||
|
||
// check if the type supports BigInts | ||
if (typeof value === "bigint" && !(typeof max === "bigint")) { | ||
throw new TypeError("can't convert BigInt to number"); | ||
} | ||
|
||
const tag = Object.entries(GITypeTag) | ||
.find(([_, name]) => name === type)?.[0]?.toLowerCase() ?? "type"; | ||
throw new RangeError(`value is out of range for ${tag}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[wrap-git] | ||
directory = gobject-introspection | ||
url = https://gitlab.gnome.org/GNOME/gobject-introspection.git | ||
revision = 1.80.1 | ||
depth = 1 | ||
|
||
[provide] | ||
program_names = g-ir-scanner, g-ir-compiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gi_dep = subproject('gobject-introspection') | ||
|
||
subdir('regress') |
Oops, something went wrong.