From dfce20013a8536f9116b8fb7faea2ce4b275eff9 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Wed, 7 Aug 2024 14:33:00 +0300 Subject: [PATCH] tests: add tests for comptime --- .github/workflows/test_gcc_windows.yml | 7 +++- .github/workflows/tests_clang_macos.yml | 7 +++- .github/workflows/tests_clang_ubuntu.yml | 7 +++- .github/workflows/tests_clang_windows.yml | 7 +++- .github/workflows/tests_gcc_macos.yml | 8 +++- .github/workflows/tests_gcc_ubuntu.yml | 9 +++- tests/comptime/match.jule | 51 +++++++++++++++++++++++ 7 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 tests/comptime/match.jule diff --git a/.github/workflows/test_gcc_windows.yml b/.github/workflows/test_gcc_windows.yml index 9895d98e9..ff4b5e50a 100644 --- a/.github/workflows/test_gcc_windows.yml +++ b/.github/workflows/test_gcc_windows.yml @@ -26,7 +26,12 @@ jobs: - name: Test - Basic Calculator run: | .\bin\julec --compiler gcc -o test tests/basic_calculator - + + - name: Test - Comptime + run: | + .\bin\julec --compiler gcc -o test tests/comptime + ./test + - name: Test - Concurrency run: | .\bin\julec --compiler gcc -o test tests/concurrency diff --git a/.github/workflows/tests_clang_macos.yml b/.github/workflows/tests_clang_macos.yml index 32f06cab8..399cb23a5 100644 --- a/.github/workflows/tests_clang_macos.yml +++ b/.github/workflows/tests_clang_macos.yml @@ -26,7 +26,12 @@ jobs: - name: Test - Basic Calculator run: | julec --compiler clang -o test tests/basic_calculator - + + - name: Test - Comptime + run: | + julec --compiler clang -o test tests/comptime + ./test + - name: Test - Concurrency run: | julec --compiler clang -o test tests/concurrency diff --git a/.github/workflows/tests_clang_ubuntu.yml b/.github/workflows/tests_clang_ubuntu.yml index 3e8c5f8ed..6bb94ba6c 100644 --- a/.github/workflows/tests_clang_ubuntu.yml +++ b/.github/workflows/tests_clang_ubuntu.yml @@ -26,7 +26,12 @@ jobs: - name: Test - Basic Calculator run: | julec --compiler clang -o test tests/basic_calculator - + + - name: Test - Comptime + run: | + julec --compiler clang -o test tests/comptime + ./test + - name: Test - Concurrency run: | julec --compiler clang -o test tests/concurrency diff --git a/.github/workflows/tests_clang_windows.yml b/.github/workflows/tests_clang_windows.yml index 2b40a2471..3e87a3ba2 100644 --- a/.github/workflows/tests_clang_windows.yml +++ b/.github/workflows/tests_clang_windows.yml @@ -26,7 +26,12 @@ jobs: - name: Test - Basic Calculator run: | .\bin\julec --compiler clang -o test tests/basic_calculator - + + - name: Test - Comptime + run: | + .\bin\julec --compiler clang -o test tests/comptime + ./test + - name: Test - Concurrency run: | .\bin\julec --compiler clang -o test tests/concurrency diff --git a/.github/workflows/tests_gcc_macos.yml b/.github/workflows/tests_gcc_macos.yml index fe1354146..0f58298e8 100644 --- a/.github/workflows/tests_gcc_macos.yml +++ b/.github/workflows/tests_gcc_macos.yml @@ -30,7 +30,13 @@ jobs: run: | julec --compiler gcc --compiler-path g++-13 -o test -t tests/basic_calculator g++-13 -w --std=c++17 -O0 -Wl,-ld_classic -o test dist/ir.cpp - + + - name: Test - Comptime + run: | + julec --compiler gcc --compiler-path g++-13 -o test -t tests/comptime + g++-13 -w --std=c++17 -O0 -Wl,-ld_classic -o test dist/ir.cpp + ./test + - name: Test - Concurrency run: | julec --compiler gcc --compiler-path g++-13 -o test -t tests/concurrency diff --git a/.github/workflows/tests_gcc_ubuntu.yml b/.github/workflows/tests_gcc_ubuntu.yml index 6098ec3ac..65f4fbe4a 100644 --- a/.github/workflows/tests_gcc_ubuntu.yml +++ b/.github/workflows/tests_gcc_ubuntu.yml @@ -25,8 +25,13 @@ jobs: - name: Test - Basic Calculator run: | - julec --compiler gcc -o test tests/basic_calculator - + julec --compiler gcc -o test tests/comptime + + - name: Test - Comptime + run: | + julec --compiler gcc -o test tests/comptime + ./test + - name: Test - Concurrency run: | julec --compiler gcc -o test tests/concurrency diff --git a/tests/comptime/match.jule b/tests/comptime/match.jule new file mode 100644 index 000000000..836482ee0 --- /dev/null +++ b/tests/comptime/match.jule @@ -0,0 +1,51 @@ +// Copyright 2024 The Jule Programming Language. +// Use of this source code is governed by a BSD 3-Clause +// license that can be found in the LICENSE file. + +use comptime for std::comptime + +fn match1() { + match comptime::Match(comptime::TypeOf(int)) { + | comptime::TypeOf(&int): + outln("foo") + | comptime::TypeOf(bool): + outln("bar") + |: + outln("baz") + } +} + +fn match2() { + match comptime::Match(20) { + | 20: + outln("foo") + | 40: + outln("bar") + |: + outln("baz") + } +} + +fn typeMatch1() { + match type comptime::Match(20) { + | int: + outln("foo") + | bool: + outln("bar") + |: + outln("baz") + } +} + +fn typeMatch2() { + match type comptime::Match(comptime::TypeOf(int)) { + | *int: + outln("foo") + | bool: + outln("bar") + |: + outln("baz") + } +} + +fn main() {} \ No newline at end of file