See Original text in context
multi sub is(Mu , Mu , = '')multi sub is(Mu , Mu , = '')
Marks a test as passed if $got
and $expected
compare positively with the eq
operator, unless $expected
is a type object, in which case ===
operator will be used instead; accepts an optional description of the test as the last argument.
NOTE: the eq
operator stringifies its operands, which means is()
is not a good function for testing more complex things, such as lists: is (1, (2, (3,))), [1, 2, 3]
passes the test, even though the operands are vastly different. For those cases, use is-deeply
routine
my ; sub factorial() ; ...;is .author, "Joe", 'Retrieving the author field';is factorial(6), 720, 'Factorial - small integer';my Int ;is , Int, 'The variable $a is an unassigned Int';
Note: if only whitespace differs between the values, is()
will output failure message differently, to show the whitespace in each values. For example, in the output below, the second test shows the literal \t
in the got:
line:
is "foo\tbar", "foo\tbaz"; # expected: 'foo baz'# got: 'foo bar'is "foo\tbar", "foo bar"; # expected: "foo bar"# got: "foo\tbar"
See Original text in context
multi sub trait_mod:<is>(Mu , Mu )
The trait is
accepts a type object to be added as a parent class of a class in its definition. To allow multiple inheritance the trait can be applied more than once. Adding parents to a class will import their methods into the target class. If the same method name occurs in multiple parents, the first added parent will win.
If no is
trait is provided the default of Any will be used as a parent class. This forces all Raku objects to have the same set of basic methods to provide an interface for introspection and coercion to basic types.
say A.new.^parents(:all).raku;# OUTPUT: «(Any, Mu)»is A is Bsay C.new.from-a();# OUTPUT: «A::from-a»
See Original text in context
proto sub trait_mod:<is>(Mu $, |)
is
applies to any kind of scalar object, and can take any number of named or positional arguments. It is the most commonly used trait, and takes the following forms, depending on the type of the first argument.