Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

concurrency:
group: test-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
go-test:
name: Go test
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Download dependencies
run: go mod download

- name: Run tests
run: go test ./...
45 changes: 45 additions & 0 deletions compiler/p0_regression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package compiler

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestP0VariadicAndCallUnpackingRegression(t *testing.T) {
t.Run("static tuple star call and keyword-only argument", func(t *testing.T) {
src := "def total(a: int, b: int, *, c: int = 3) -> int:\n" +
" return a + b + c\n" +
"args: tuple[int, int] = (1, 2)\n" +
"print(str(total(*args)))\n" +
"print(str(total(*args, c=4)))\n"
require.Equal(t, "6\n7\n", run(t, src))
})

t.Run("duplicate keyword from positional binding is rejected", func(t *testing.T) {
errs := checkOnly(t, "def f(a: int) -> int:\n"+
" return a\n"+
"print(str(f(1, a=2)))\n")
require.NotEmpty(t, errs)
})
}

func TestP0MatchStarAndRestPatternsRegression(t *testing.T) {
t.Run("list starred rest capture", func(t *testing.T) {
src := "xs: list[int] = [1, 2, 3]\n" +
"match xs:\n" +
" case [head, *tail]:\n" +
" print(str(head))\n" +
" print(str(tail[0]))\n"
require.Equal(t, "1\n2\n", run(t, src))
})

t.Run("mapping rest capture copies unconsumed keys", func(t *testing.T) {
src := "data: dict[str, int] = {\"x\": 1, \"y\": 2}\n" +
"match data:\n" +
" case {\"x\": x, **rest}:\n" +
" print(str(x))\n" +
" print(str(rest[\"y\"]))\n"
require.Equal(t, "1\n2\n", run(t, src))
})
}
Loading