Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Test List

The following table lists all tests included in this documentation.

124 tests have been evaluated with version 0.2.19 of microcad.

Click on the test names to jump to file with the test or click the buttons to get the logs.

ResultSourceName
testauto_convert
testbody_assignment_const
testbody_assignment_prop
testbody_assignment_var
testbody_expression
testbody_expression_model
testbody_function
testbody_if
testbody_init
testbody_marker
testbody_module
testbody_pub_use
testbody_return
testbody_use
testbody_workbench
testbuiltin_modules
testcondition_return
testempty_op
testfunction
testfunction_assignment_const
testfunction_assignment_prop
testfunction_assignment_var
testfunction_expression
testfunction_expression_model
testfunction_function
testfunction_if
testfunction_if_result
testfunction_init
testfunction_missing
testfunction_mixed
testfunction_module
testfunction_pub_use
testfunction_return
testfunction_return_value
testfunction_use
testfunction_value
testfunction_workbench
testgroup
testgroup_assignment
testinit_assignment_const
testinit_assignment_prop
testinit_assignment_var
testinit_expression
testinit_expression_model
testinit_function
testinit_if
testinit_init
testinit_module
testinit_pub_use
testinit_return
testinit_use
testinit_workbench
testlocals_unused
testlogo
testmethod_call
testmod_external
testmod_external_root
testmodule_assignment_const
testmodule_assignment_prop
testmodule_assignment_var
testmodule_expression
testmodule_expression_model
testmodule_function
testmodule_if
testmodule_init
testmodule_module
testmodule_pub_use
testmodule_return
testmodule_use
testmodule_workbench
testoperation_no_body
testoperation_with_body
testpre_init_assignment_const
testpre_init_assignment_prop
testpre_init_assignment_var
testpre_init_expression
testpre_init_expression_model
testpre_init_function
testpre_init_if
testpre_init_init
testpre_init_module
testpre_init_pub_use
testpre_init_return
testpre_init_use
testpre_init_workbench
testscopes
testsketch_missing_semicolon
testsketch_with_body
testsketch_with_empty_body
testsource_assignment_const
testsource_assignment_prop
testsource_assignment_var
testsource_expression
testsource_expression_model
testsource_function
testsource_if
testsource_init
testsource_module
testsource_pub_use
testsource_return
testsource_use
testsource_workbench
testuse_all_local
testuse_as_test
testuse_local
testuse_statement_pub_in_module
testuse_statement_test
testuse_test
testvalue_declarations
testvisibility
testworkbench_assignment_const
testworkbench_assignment_prop
testworkbench_assignment_var
testworkbench_expression
testworkbench_expression_model
testworkbench_function
testworkbench_if
testworkbench_init
testworkbench_marker
testworkbench_module
testworkbench_pub_use
testworkbench_return
testworkbench_use
testworkbench_workbench

Automatic conversion of values when matching arguments

test

fn f( x: Scalar ) { _ = x; }
f(x=1);
f(x=[1]);
f(x="");    // error
f("");      // error
f(1.0);
f(1);
f([1.0]);
f([1]);

fn g( x: Integer ) { _ = x; }
g(x=1.0);   // error
g(x="");    // error
g("");      // error
g(1.0);     // error
g([1.0]);   // error
g(1);
g([1]);

fn h( x: String ) { _ = x; }
h(x=1.0);   // error
h(x="");
h(x=[""]);
h("");
h([""]);
h(1.0);     // error
h([1.0]);   // error

µcad logo

test

test

Conditions

test

fn f(x: Integer) {
    if x == 5 or x == 4 {
        return "match";
    } else if x > 0 and x < 4 {
        return "no match";
    } else {
        return "invalid";
    }
}

std::print(f(5));  // prints "match"

Ambiguous Look Up for properties/locals and operations

test

op scale() {}
sketch Sketch(scale: Scalar) { std::geo2d::Rect(size = scale * 40mm) }
Sketch(4.0);

Load an external module within MD test

test

mod external;
std::debug::assert_valid(external::a);

test

// file: external.µcad
pub const a =1;

Functions

test

// function definition
fn f() {}
// call
f();

test

// parameter
fn f(n: Scalar) {
    // result value
    n+1
}
use std::debug::*;
assert_eq([ f(1), 2 ]);
assert_eq([ f(4), 5 ]);

test

fn f(n: Scalar) {
    return n+1;
}
use std::debug::*;
assert_eq([ f(1), 2 ]);
assert_eq([ f(4), 5 ]);

test

fn f(n: Scalar) {
    if n > 3 {
        n-1
    } else {
        n+1
    }
}
use std::debug::*;
assert_eq([ f(1), 2 ]);
assert_eq([ f(4), 3 ]);

test

fn f(n: Scalar) {
    if n > 3 {
        return n-1;
    }
    n+1
}
use std::debug::*;
assert_eq([ f(1), 2 ]);
assert_eq([ f(4), 3 ]);

test

fn f(n: Scalar) { // error: not all paths return a value
    if n > 3 {
         n-1
    }
}
use std::debug::*;
assert_eq([ f(1), 2 ]);
assert_eq([ f(4), 3 ]);

Modules

test

mod a {
    pub mod b {
        pub mod c {
            pub part M1() {}
        }
    }

    pub part M2() {}
}

a::b::c::M1();
a::M2();

Scope tests

Scopes

test

a = 1;

__builtin::debug::assert_valid(a);
__builtin::debug::assert_invalid(b);
__builtin::debug::assert_invalid(c);

{
    __builtin::debug::assert_valid(a);
    __builtin::debug::assert_invalid(b);
    __builtin::debug::assert_invalid(c);

    b = 2;

    __builtin::debug::assert_valid(a);
    __builtin::debug::assert_valid(b);
    __builtin::debug::assert_invalid(c);

    c = 3;

    __builtin::debug::assert_valid(a);
    __builtin::debug::assert_valid(b);
    __builtin::debug::assert_valid(c);
};

__builtin::debug::assert_valid(a);
__builtin::debug::assert_invalid(b);
__builtin::debug::assert_invalid(c);

Usage of semicolon with Workbenches

test

use std::geo2d::Circle;
use std::ops::translate;

{ // op with body
    Circle(radius = 5mm);
}.translate(y=[-34mm/2 , 34mm/2]);

test

use std::geo2d::Circle;
use std::ops::translate;

 // op without body
Circle( radius = 5mm )
    .translate(y = [-34mm/2 , 34mm/2]);

test

use std::geo2d::Circle;
use std::ops::translate;

{
    Circle(radius = 5mm) // missing semicolon is ok.
}.translate(y=[-34mm/2 , 34mm/2]);

test

{}.std::ops::translate(x = 5mm) // warning: Calling operation on empty geometry

test

use std::geo2d::Circle;

Circle(radius = 2mm) { Circle(radius = 1mm); } // parse_error: sketch with body

test

std::ops::translate(x = 3.0mm); // error: Cannot call operation without workpiece. 
{}.std::ops::translate(x = 3.0mm);  // warning: Calling operation on empty geometry

test

use std::geo2d::Circle;
use std::ops::translate;

// group
{ 
    Circle(radius = 1mm); 
    Circle(radius = 2mm); 
}

test

use std::geo2d::Circle;
use std::ops::translate;

// assignment + group
a = { 
    Circle(radius = 1mm); 
    Circle(radius = 2mm); 
};

Statement Usage

The following table shows which elements (rows) may occur in which Context (columns):

Context/ElementSource FileModulePre-InitInitWork-benchBodyFunc-tion
sketch, part, opyesyes-----
modyesyes-----
fnyesyes-----
init--yes-yes--
useyesyesyesyesyesyesyes
pub useyesyes-----
return------yes
ifyes---yesyesyes
@input----yes?yes?-
x = 1yesyes-yesyesyesyes
constyesyes-----
prop----yes--
expressionyes---yesyesyes
TestTestTestTestTestTestTest

Source

test

sketch F() {} F();

test

mod m {}

test

fn f() {} f();

test

init() {} // error

test

use std;

test

pub use std;

test

return 1;  // error

test

if std::math::PI == 3 { __builtin::geo2d::Circle(radius=1mm); }

test

const B = 1;

test

a = 1;

test

prop a = 1;  // error

test

1 + 2;

test

__builtin::geo2d::Circle(radius=1mm);

Module

test

mod k {
  sketch F() {}
}

test

mod k {
  mod m {}
}

test

mod k {
  fn f() {}
}

test

mod k {
  init() { }  // error
}

test

mod k {
  use std::geo2d;
}

test

mod k {
  pub use std::geo2d;
}

test

mod k {
  return 1;  // error
}

test

mod k {
  if std::math::PI == 3 { __builtin::geo2d::Circle(radius=1); }  // error
}

test

mod k {
  const B = 1;
}

test

mod k {
  a = 1; // error
}

test

mod k {
  prop a = 1;  // error
}

test

mod k {  // warning
  1 + 2; // error
}

test

mod k { // warning
  __builtin::geo2d::Circle(radius=1mm); // error
}

Pre-Init

test

sketch K() { 
  sketch F() {} K();  // error
init(l:Length) {} } K();

test

sketch K() { 
  mod m {}   // error
init(l:Length) {} } K();

test

sketch K() { 
  fn f() {} f();   // error
init(l:Length) {} } K();

test

sketch K() { 
  init() {}
init(l:Length) {} } K();

test

sketch K() { 
  use std;
init(l:Length) {} } K();

test

sketch K() { 
  pub use std; // error
init(l:Length) {} } K();

test

sketch K() { 
  return 1; // error
init(l:Length) {} } K();

test

sketch K() { 
  if std::math::PI == 3 { } // error
init(l:Length) {} } K();

test

sketch K() { 
  const B = 1;
init(l:Length) {} } K();

test

sketch K() { 
  a = 1; // error
init(l:Length) {} } K();

test

sketch K() {
  prop a = 1; // error
init(l:Length) {} } K();

test

sketch K() { 
  1 + 2; // error
init(l:Length) {} } K();

test

sketch K() { 
  __builtin::geo2d::Circle(radius=1mm); // error
init(l:Length) {} }

Init

test

sketch K() { init(l:Length) { // warning
  sketch F() {} // error
} } K(1cm);

test

sketch K() { init(l:Length) { // warning
  mod m {} // error
} } K(1cm);

test

sketch K() { init(l:Length) { // warning
  fn f() {} // error
} } K(1cm);

test

sketch K() { init(l:Length) { // warning
  init() {} // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  use std;
} } K(1cm);

test

sketch K() { init(l:Length) { // warning
  pub use std; // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  return l; // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  if std::math::PI == l { } // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  const B = l; // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  a = l;
} } K(1cm);

test

sketch K() { init(l:Length) {
  prop a = l; // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  l + 2; // error
} } K(1cm);

test

sketch K() { init(l:Length) {
  __builtin::geo2d::Circle(radius=l); // error
} } K(1cm);

Workbench

test

sketch K() {
  sketch F() {} F(); // error
} K();

test

sketch K() {
  mod m {} // error
} K();

test

sketch K() {
  fn f() {} f();
} K();

test

sketch K() {
  init() {}
} K();

test

sketch K() {
  use std;
} K();

test

sketch K() {
  pub use std; // error
} K();

test

sketch K() {
  return 1; // error
} K();

test

sketch K() {
  if std::math::PI == 3 { }
} K();

test

sketch K() {
  @input
} K();

test

sketch K() {
  const B = 1;
} K();

test

sketch K() {
  a = 1;
} K();

test

sketch K() {
  prop a = 1;
} K();

test

sketch K() {
  1 + 2;
} K();

test

sketch K() {
  __builtin::geo2d::Circle(radius=1mm);
} K();

Body

test

{
  sketch F() {} // error
}

test

{
  mod m {} // error
}

test

{
  fn f() {} f(); // error
}

test

{
  init() {} // error
}

test

{
  use std;
}

test

{
  pub use std; // error
}

test

{
  return 1; // error
}

test

{
  if std::math::PI == 3 { }
}

test

{
  @input
}

test

{
  const B = 1; // error
}

test

{
  a = 1;
}

test

{
  prop a = 1; // error
}

test

{
  1 + 2;
}

test

{
  __builtin::geo2d::Circle(radius=1mm);
}

Function

test

fn f() {
  sketch S() {} // error
} f();

test

fn f() {
  mod m {} // error
} f();

test

fn f() {
  fn f() {} // error
} f();

test

fn f() {
  init() {} // error
} f();

test

fn f() {
  use std;
} f();

test

fn f() {
  pub use std; // error
} f();

test

fn f() {
  return 1;
} f();

test

fn f() {
  if std::math::PI == 3 { __builtin::geo2d::Circle(radius=1); }
} f();

test

fn f() {
  const B = 1; // error
} f();

test

fn f() {
  a = 1;
} f();

test

fn f() {
  prop a = 1; // error
} f();

test

fn f() {
  1 + 2;
} f();

test

fn f() {
  __builtin::geo2d::Circle(radius=1mm);
} f();

Use statement tests

test

// use debug from `std/module.µcad`
use std::debug::assert;
assert(true);

// use all symbols from std::debug for test checks
use std::debug::*;

// use symbol `circle` in file `geo2d.µcad`
use std::geo2d::Circle;
assert_valid(Circle);

// use all symbols in file `geo3d.µcad`
use std::geo3d::*;
assert_valid(Sphere);
assert_valid(Cube);

// alias `Circle` in `std/geo2d/mod.µcad` into `foo`
use std::geo2d::Circle as foo;
assert_valid(foo);

// use print from `std/module.µcad`
use std::print;
assert_valid(print);
print("Hello");

// public use operation from `std/module.µcad`
pub use std::ops;
assert_valid(ops);
assert_valid(use_test::ops);

part MyPart() {
    Circle(radius=1);
    Sphere(radius=1);
}

assert_valid(MyPart);

test

use std::geo2d::*; 
use Rect as Cap;

Cap(width=1mm,height=1mm);

test

// use symbol `circle` in file `geo2d.µcad`
use std::geo2d::Circle;
// use all symbols in file `geo3d.µcad`
use std::geo3d::*;
// alias `bar` in `std/text/foo.µcad` into `baz`
use std::math::abs as baz;
// use print from `std/module.µcad`
use std::print;
// public use operation from `std/module.µcad`
pub use std::ops;

// use debug from `std/module.µcad`
use std::debug;
debug::assert(true);

part my_part3d() { Sphere(radius=1mm); }
part my_part2d() { Circle(radius=1mm); }

x = my_part2d();
y = my_part3d();
z = baz(-1.0);

test

fn f() {
    use std::math::abs;
    x = abs(-1.0);
    return x;
}
f();

test

fn f() {
    use std::math::*;
    x = abs(-1.0);
    return x;
}
f();

test

mod my {
    mod name {
        pub mod space {
            pub use std::geo2d::*;
        }
    }
    pub use name::space::*;
}

my::Circle(r = 4mm);
my::Rect(size = 40mm);

Value Declarations

Keyword(s)ContextDescriptionExample
-source, workbench, functionlocal valuea=1
-initproperty (if in building plan), else local valuea=1
propworkbenchmodel propertyprop a=1
constmoduleprivate module valueconst a=1;
pub, (pub const)modulepublic module valuepub a=1;, pub const a=1;
usemodule, source, workbench, function, initprivate usageuse std::geo3d;
pub usemodule, sourcepublic usagepub use std::geo3d;
fnmodule, source, workbenchprivate functionfn() {}
pub fnmodule, sourcepublic functionpub fn() {}

test

use std::debug::*;

mod module {
    
    use std::debug::*;

    // private module variable
    const value = 1;
    // public module variable
    pub pub_value = 2;

    pub mod pub_sub_module {
        // pre-init code
        use std::debug::*;

        // private module variable
        const value = 3;
        // public module variable
        pub pub_value = 4;

        // private workbench
        sketch PrivateWorkbench() {}

        // public workbench
        pub sketch Workbench(param = 5) {
            const sketch_local = 6;

            init(alt_param = 7) {
                init_local = 8;

                assert_eq([super::value, 1]);
                assert_eq([super::pub_value, 2]);
                assert_eq([value, 3]);
                assert_eq([pub_value, 4]);
                assert_invalid(param);
                assert_eq([sketch_local, 6]);
                assert_eq([alt_param, 7]);
                assert_eq([init_local, 8]);

                prop param = 5; // needed to compile
            }

            // property of sketch
            prop property = 9;

            // post init code
            assert_eq([super::value,1]);
            assert_eq([super::pub_value, 2]);
            assert_eq([value, 3]);
            assert_eq([pub_value, 4]);
            assert_eq([param, 5]);
            assert_eq([sketch_local, 6]);
            assert_invalid(alt_param);
            assert_invalid(init_local);
            assert_eq([property, 9]);

            function();
        }

        fn function(fn_param = 10) {
            assert_eq([super::value, 1]);
            assert_eq([super::pub_value, 2]);
            assert_eq([value, 3]);
            assert_eq([pub_value, 4]);
            assert_invalid(param);
            // assert_invalid(Workbench);
            assert_eq([fn_param, 10]);

            return 0;
        }
    }

    pub fn function(fn_param = 11) {
        assert_eq([value, 1]);
        assert_eq([pub_value, 2]);
        assert_invalid(pub_sub_module::value);
        assert_eq([pub_sub_module::pub_value, 4]);
        assert_invalid(Workbench);
        assert_invalid(PrivateWorkbench);
        assert_eq([fn_param, 11]);
        
        return 0;
    }
}

// source file code 
assert_invalid(module::value);
assert_eq([module::pub_value, 2]);
assert_invalid(module::pub_sub_module::value);
assert_eq([module::pub_sub_module::pub_value, 4]);
assert_eq([module::pub_sub_module::Workbench().property, 9]);
assert_invalid(module::pub_sub_module::PrivateWorkbench);
assert_eq([module::function(), 0]);

Visibility

test

mod my {
    mod mod_private {
        pub const_public = 1;
        const const_private = 1;
    }
    pub mod mod_public {
        pub const_public = 1;
        const const_private = 1;
    }
}

__builtin::debug::assert_valid(my::mod_public::const_public);
__builtin::debug::assert_invalid(my::mod_public::const_private);
__builtin::debug::assert_invalid(my::mod_private::const_public);
__builtin::debug::assert_invalid(my::mod_private::const_private);