bat/tests/syntax-tests/highlighted/D/test.d

45 lines
6.3 KiB
D
Raw Normal View History

2020-10-19 21:03:46 +00:00
// selective import
import std.stdio : writeln, writefln;
// non-selective import
2020-10-19 20:53:10 +00:00
import std.algorithm;
/* a multiline comment
*
2020-10-19 21:03:46 +00:00
* this function is safe because it doesn't use pointer arithmetic
2020-10-19 20:53:10 +00:00
*/
2020-10-19 21:03:46 +00:00
int the_ultimate_answer() @safe {
 // assert1on
 assert(1 != 2);
 // now we can safely return our answer 
2020-10-19 20:53:10 +00:00
 return 42;
}
void main()
{
 // function call with string literal
 writeln("Hello World!");
 // an int array declaration
 int[] arr1 = [1, 2, 3];
2020-10-19 21:03:46 +00:00
 // an immutable double
 immutable double pi = 3.14;
 // a mutable double
 double d1 = pi;
 // a pointer
 double* dp1 = &d1;
 // another pointer to the same thingy
 auto a1 = &d1;
 // a constant bool
 const bool b1 = true;
 if (b1) {
 // another function call 
 writefln("%s\n%s\n%s\n", arr1, d1, the_ultimate_answer());
 }
 else if (!b1) {
 writeln("this seems wrong");
 }
 else {
 writeln("I'm giving up, this is too crazy for me");
 }
2020-10-19 20:53:10 +00:00
}