diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07fb36b9..5cac8f37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,34 +1,34 @@ name: CI - -on: - push: - branches: [master] - pull_request: +on: [push] jobs: - build: + test: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: purescript-contrib/setup-purescript@main - with: - purescript: "unstable" + - name: Install Lua interpreter + uses: leafo/gh-actions-lua@v11 - - uses: actions/setup-node@v2 + - name: Set up Node 20 + uses: actions/setup-node@v4 with: - node-version: "14.x" + node-version: "20.x" - - name: Install dependencies + - name: Set up Purescript and spago-legacy run: | - npm install -g bower - npm install - bower install --production + npm i -g purescript + npm i -g spago-legacy - - name: Build source - run: npm run-script build + - name: Download pslua + run: wget -c https://github.com/Unisay/purescript-lua/releases/download/0.2/pslua-linux_x86_64.tar.gz -O - | tar -xz - - name: Run tests - run: | - bower install - npm run-script test --if-present + - run: mkdir bin + - run: mv pslua bin + + - name: Put pslua on PATH + run: realpath bin >> $GITHUB_PATH + + - name: Build and test + run: ./test.sh diff --git a/LICENSE b/LICENSE index 311379c1..b028b9cb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2018 PureScript +Copyright 2018-2025 PureScript, Unisay, UnrelatedString Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index d225b5e7..ce5fb7be 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -# purescript-prelude +# purescript-lua-prelude -[![Latest release](http://img.shields.io/github/release/purescript/purescript-prelude.svg)](https://github.com/purescript/purescript-prelude/releases) -[![Build status](https://github.com/purescript/purescript-prelude/workflows/CI/badge.svg?branch=master)](https://github.com/purescript/purescript-prelude/actions?query=workflow%3ACI+branch%3Amaster) +[![Latest release](http://img.shields.io/github/release/Unisay/purescript-lua-prelude.svg)](https://github.com/Unisay/purescript-lua-prelude/releases) +[![Build status](https://github.com/Unisay/purescript-lua-prelude/workflows/CI/badge.svg?branch=master)](https://github.com/Unisay/purescript-lua-prelude/actions?query=workflow%3ACI+branch%3Amain) [![Pursuit](https://pursuit.purescript.org/packages/purescript-prelude/badge)](https://pursuit.purescript.org/packages/purescript-prelude) -The PureScript prelude. +The PureScript prelude for Lua. + ## Installation @@ -14,4 +15,4 @@ spago install prelude ## Documentation -Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-prelude). +Module documentation (for the implementation of the same API for the JavaScript backend) is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-prelude). diff --git a/spago-legacy b/spago-legacy new file mode 100755 index 00000000..69e71943 --- /dev/null +++ b/spago-legacy @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +if spago-legacy --version > /dev/null; then + spago-legacy "$@" +else + spago "$@" +fi diff --git a/spago.dhall b/spago.dhall index 9b25c8ac..a827011c 100644 --- a/spago.dhall +++ b/spago.dhall @@ -1,5 +1,6 @@ { name = "purescript-lua-prelude" , dependencies = [ ] : List Text , packages = ./packages.dhall -, sources = [ "src/**/*.purs" ] +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +, backend = "pslua --foreign-path . --lua-output-file output/main.lua" } diff --git a/test.dhall b/test.dhall new file mode 100644 index 00000000..732b11b3 --- /dev/null +++ b/test.dhall @@ -0,0 +1,9 @@ +let normal = ./spago.dhall +in normal // + { backend = '' + pslua \ + --foreign-path . \ + --lua-output-file output/test.lua \ + --entry Test.Main + '' + } diff --git a/test.sh b/test.sh new file mode 100755 index 00000000..3299039e --- /dev/null +++ b/test.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +./spago-legacy -x test.dhall build && lua output/test.lua && echo Tests passed! diff --git a/test/Test/Main.lua b/test/Test/Main.lua new file mode 100644 index 00000000..e94af12e --- /dev/null +++ b/test/Test/Main.lua @@ -0,0 +1,39 @@ +return { + testNumberShow = (function(showNumber) + return function() + cases = { + {0.0, "0.0"}, + {1.0, "1.0"}, + {-1.0, "-1.0"}, + {500.0, "500.0"}, + + -- Outside Int range + {1e10, "10000000000.0"}, + {1e10 + 0.5, "10000000000.5"}, + {-1e10, "-10000000000.0"}, + {-1e10 - 0.5, "-10000000000.5"}, + + -- With exponent + {1e21, "1e+21"}, + {1e-21, "1e-21"}, + + -- With decimal and exponent + {1.5e21, "1.5e+21"}, + {1.5e-10, "1.5e-10"}, + + {nan, "NaN"}, + {math.huge, "Infinity"}, + {-math.huge, "-Infinity"}, + } + + for case in cases do + input = case[0] + expected = case[1] + actual = showNumber(input) + if expected ~= actual then + error("For "..input..", expected "..expected..", got: "..actual..".") + end + end + end + end) +} diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 13ea2cce..f0e1652f 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -6,7 +6,7 @@ import Data.Ord (abs, signum) import Data.Reflectable (reflectType, reifyType) import Prim.Boolean (True, False) import Prim.Ordering (LT, GT, EQ) -import Test.Data.Generic.Rep (testGenericRep) +--import Test.Data.Generic.Rep (testGenericRep) import Test.Utils (AlmostEff, assert) import Type.Proxy (Proxy(..)) @@ -18,7 +18,7 @@ main = do testIntDivMod testIntDegree testRecordInstances - testGenericRep + --testGenericRep testReflectType testReifyType testSignum diff --git a/test/Test/Utils.lua b/test/Test/Utils.lua new file mode 100644 index 00000000..275fef6f --- /dev/null +++ b/test/Test/Utils.lua @@ -0,0 +1,7 @@ +return { + throwErr = (function(msg) + return function() + error(msg) + end + end), +}