Skip to content

Commit

Permalink
Merge pull request #762 from dictu-lang/feature/assert_silence
Browse files Browse the repository at this point in the history
Allow silencing of unittest assertions
  • Loading branch information
Jason2605 authored Dec 9, 2024
2 parents ecdba28 + d09bee1 commit f07699f
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 79 deletions.
6 changes: 3 additions & 3 deletions docs/docs/built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The path name of the compilation unit.

Global functions which are built into Dictu.

### print(...values)
### print(...Value)

Prints a given list of values to stdout.

Expand All @@ -35,7 +35,7 @@ print("test"); // "test"
print(10, "test", nil, true); // 10, "test", nil, true
```

### printError(...values)
### printError(...Value)

Prints a given list of values to stderr.

Expand All @@ -55,7 +55,7 @@ input();
input("Input: ");
```

### type(value) -> String
### type(Value) -> String

Returns the type of a given value as a string.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/collections/dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var myDict = {"key": 1, "key1": true};
myDict["key2"] = nil; // {"key": 1, "key1": true, "key2": nil}
```

### dict.get(String, value: default -> Optional) -> Dict
### dict.get(String, Value: default -> Optional) -> Dict

Returns the dictionary value at the given key, or returns the default value if the key does
not exist in the dictionary. If the key does not exist and no default is provided `nil` is returned.
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/collections/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ If you want to return only part of a list, you slice it! To slice a list, use sq
```

### Adding to lists
#### list.push(value)
#### list.push(Value)

To add append a new value to a list, use the `.push()` method.

Expand All @@ -61,7 +61,7 @@ myList.push(10); // [10]
myList.push(11); // [10, 11]
```

#### list.insert(value, Number)
#### list.insert(Value, Number)

To insert a value into a list at a given index without replacing the value use .insert().

Expand Down Expand Up @@ -125,7 +125,7 @@ Converts a list to a boolean. A list is a "truthy" value when it has a length gr
[[]].toBool(); // true
```

### list.contains(value) -> Boolean
### list.contains(Value) -> Boolean

To check if a value contains within a list we use `.contains()`

Expand All @@ -149,7 +149,7 @@ print(myList.join("-")); // "1-2-3"
print([].join("delimiter")); // ""
```

### list.remove(value)
### list.remove(Value)

To remove a value from a list use `.remove()`. If the value does not exist within
the list a runtime error occurs. Use together with [list.contains()](#listcontainsvalue).
Expand All @@ -165,7 +165,7 @@ myList.remove(1);
print(myList); // [2]
```

### list.pop(Number: index -> Optional) -> value
### list.pop(Number: index -> Optional) -> Value

To remove a value from a list, with an optional index, use `.pop()`

Expand Down Expand Up @@ -294,7 +294,7 @@ Note: `.filter()` returns a new list.
print([1, 2, 3, 4, 5].filter(def (x) => x > 2)); // [3, 4, 5]
```

### list.reduce(Func, value: initial -> Optional) -> List
### list.reduce(Func, Value: initial -> Optional) -> List

To reduce a list down to a single value we use `.reduce()`. Reduce expects at least one parameter which is a callback
that will be executed on each item of the list. The value of the callback function is returned and saved for the next
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/collections/sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mySet.add("Dictu!");
mySet.len(); // 1
```

### set.add(value)
### set.add(Value)

Adding to sets is just a case of passing a value to .add()

Expand All @@ -82,7 +82,7 @@ var mySet = set("foo", "bar", 123);
const values = mySet.values(); // ["foo", "bar", 123]
```

### set.contains(value) -> Boolean
### set.contains(Value) -> Boolean

To check if a set contains a value use `.contains()`

Expand All @@ -93,7 +93,7 @@ print(mySet.contains("Dictu!")); // true
print(mySet.contains("Other!")); // false
```

### set.containsAll(value) -> Boolean
### set.containsAll(Value) -> Boolean

To check if a set contains all elements in a given list use `.containsAll()`

Expand All @@ -104,7 +104,7 @@ print(mySet.containsAll([1,2,3])); // true
print(mySet.containsAll(["one",1,2,3,"x"])); // false
```

### set.remove(value)
### set.remove(Value)

To remove a value from a set use `.remove()`.

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/standard-lib/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import IO;
| ---------- | ----------------------------------- |
| IO.devNull | Provides access to the null device. |

### IO.print(...values) -> Nil
### IO.print(...Value) -> Nil

Prints a given list of values to stdout.

Expand All @@ -39,7 +39,7 @@ IO.print(0);
// 0
```

### IO.println(...values) -> Nil
### IO.println(...Value) -> Nil

Prints a given list of values to stdout with an appended newline character.

Expand All @@ -48,7 +48,7 @@ IO.println("Dictu!");
// Dictu!
```

### IO.eprint(...values) -> Nil
### IO.eprint(...Value) -> Nil

Prints a given list of values to stderr.

Expand All @@ -57,7 +57,7 @@ IO.eprint(0);
// 0
```

### IO.eprintln(...values) -> Nil
### IO.eprintln(...Value) -> Nil

Prints a given list of values to stderr with an appended newline character.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/random.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Random.range(1, 5); // 4
Random.range(0, 2); // 1
```

### Random.select(List) -> value
### Random.select(List) -> Value

Returns a value randomly selected from the list.

Expand Down
22 changes: 13 additions & 9 deletions docs/docs/standard-lib/unittest.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,27 @@ file.du
```

## Assertions
### assertEquals(value, value)

Assertions allow you to pass an optional silent argument to them that will allow you to silence them when successful
on an assertion by assertion basis rather than the whole test suite like `onlyFailures` would do.

### assertEquals(Value, Value, silent: Boolean -> Optional)

This helper method ensures that both values passed in equal each other.

### assertNotEquals(value, value)
### assertNotEquals(Value, Value, silent: Boolean -> Optional)

This helper method ensures that both values passed in do not equal each other.

### assertNil(value)
### assertNil(Value, silent: Boolean -> Optional)

This helper method ensures that the value passed in is equal to nil.

### assertNotNil(value)
### assertNotNil(Value, silent: Boolean -> Optional)

This helper method ensures that the value passed in is not equal to nil.

### assertType(value, value)
### assertType(Value, Value, silent: Boolean -> Optional)

This helper method checks the type of the first value is equal to the type as a string.

Expand All @@ -428,24 +432,24 @@ this.assertType("Dictu", "string");
this.assertType(10, "number");
```

### assertTruthy(value)
### assertTruthy(Value, silent: Boolean -> Optional)

This helper method ensures that the value passed in would evaluate to true.

Note: This is not the same as equaling `true`.

### assertFalsey(value)
### assertFalsey(Value, silent: Boolean -> Optional)

This helper method ensures that the value passed in would evaluate to false.

Note: This is not the same as equaling `false`.

### assertSuccess(value)
### assertSuccess(Value, silent: Boolean -> Optional)

This helper method ensures that the value passed in is a `Result` type in
a `Success` state.

### assertError(value)
### assertError(Value, silent: Boolean -> Optional)

This helper method ensures that the value passed in is a `Result` type in
an `Error` state.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Strips whitespace from both sides of a string and returns the result.
" Dictu ".strip(); // "Dictu"
```

### string.format(...value: args...) -> String
### string.format(...Value: args) -> String

This method will replace any instances of `{}` with the provided parameters. It also casts all arguments to strings.

Expand Down
44 changes: 22 additions & 22 deletions src/optionals/unittest/unittest-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
" }\n" \
" }\n" \
"\n" \
" printResult(success, errorMsg) {\n" \
" printResult(success, errorMsg, silent) {\n" \
" if (success) {\n" \
" this.results['passed'] += 1;\n" \
"\n" \
" if (not (this.onlyFailures or this.forceOnlyFailures)) {\n" \
" if (not (this.onlyFailures or this.forceOnlyFailures) and not silent) {\n" \
" print('{}Success.'.format(UnitTest.ASSERTION_PADDING));\n" \
" }\n" \
" } else {\n" \
Expand All @@ -97,51 +97,51 @@
" }\n" \
" }\n" \
"\n" \
" assertEquals(value, expected) {\n" \
" this.printResult(value == expected, 'Failure: {} is not equal to {}.'.format(value, expected));\n" \
" assertEquals(value, expected, silent = false) {\n" \
" this.printResult(value == expected, 'Failure: {} is not equal to {}.'.format(value, expected), silent);\n" \
" }\n" \
"\n" \
" assertNotEquals(value, expected) {\n" \
" this.printResult(value != expected, 'Failure: {} is equal to {}.'.format(value, expected));\n" \
" assertNotEquals(value, expected, silent = false) {\n" \
" this.printResult(value != expected, 'Failure: {} is equal to {}.'.format(value, expected), silent);\n" \
" }\n" \
"\n" \
" assertNil(value) {\n" \
" this.printResult(value == nil, 'Failure: {} is not nil.'.format(value));\n" \
" assertNil(value, silent = false) {\n" \
" this.printResult(value == nil, 'Failure: {} is not nil.'.format(value), silent);\n" \
" }\n" \
"\n" \
" assertNotNil(value) {\n" \
" this.printResult(value != nil, 'Failure: Should not be nil.');\n" \
" assertNotNil(value, silent = false) {\n" \
" this.printResult(value != nil, 'Failure: Should not be nil.', silent);\n" \
" }\n" \
"\n" \
" assertType(value, expected) {\n" \
" assertType(value, expected, silent = false) {\n" \
" const valType = type(value);\n" \
" this.printResult(valType == expected, 'Failure: {}({}) is not of type {}.'.format(value, valType, expected));\n" \
" this.printResult(valType == expected, 'Failure: {}({}) is not of type {}.'.format(value, valType, expected), silent);\n" \
" }\n" \
"\n" \
" assertTruthy(value) {\n" \
" this.printResult(value, 'Failure: {} is not Truthy.'.format(value));\n" \
" assertTruthy(value, silent = false) {\n" \
" this.printResult(value, 'Failure: {} is not Truthy.'.format(value), silent);\n" \
" }\n" \
"\n" \
" assertFalsey(value) {\n" \
" this.printResult(not value, 'Failure: {} is not Falsey.'.format(value));\n" \
" assertFalsey(value, silent = false) {\n" \
" this.printResult(not value, 'Failure: {} is not Falsey.'.format(value), silent);\n" \
" }\n" \
"\n" \
" assertSuccess(value) {\n" \
" assertSuccess(value, silent = false) {\n" \
" if (type(value) != 'result') {\n" \
" this.printResult(false, 'Failure: {} is not a Result type.'.format(value));\n" \
" this.printResult(false, 'Failure: {} is not a Result type.'.format(value), silent);\n" \
" return;\n" \
" }\n" \
"\n" \
" this.printResult(value.success(), 'Failure: {} is not a Result type in a success state.'.format(value));\n" \
" this.printResult(value.success(), 'Failure: {} is not a Result type in a success state.'.format(value), silent);\n" \
" }\n" \
"\n" \
" assertError(value) {\n" \
" assertError(value, silent = false) {\n" \
" if (type(value) != 'result') {\n" \
" this.printResult(false, 'Failure: {} is not a Result type.'.format(value));\n" \
" this.printResult(false, 'Failure: {} is not a Result type.'.format(value), silent);\n" \
" return;\n" \
" }\n" \
"\n" \
" this.printResult(not value.success(), 'Failure: {} is not a Result type in an error state.'.format(value));\n" \
" this.printResult(not value.success(), 'Failure: {} is not a Result type in an error state.'.format(value), silent);\n" \
" }\n" \
"}\n" \

Loading

0 comments on commit f07699f

Please sign in to comment.