true 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  // =============
3
3
 
4
4
  @import 'true/settings';
5
+ @import 'true/context';
5
6
  @import 'true/utilities';
6
7
  @import 'true/messages';
7
8
  @import 'true/results';
@@ -2,78 +2,84 @@
2
2
  // ======
3
3
 
4
4
 
5
+
6
+ // Assert True
7
+ // -----------
5
8
  /// Assert that a parameter is `true`
6
9
  /// @access public
7
10
  /// @group testing
8
11
  /// @param {*} $assert - Assert
9
12
  /// @param {String} $description [''] - Assert description
10
- /// @require {mixin} _true-fail-details
11
- /// @require {mixin} _true-assert-start
12
- /// @require {mixin} _true-assert-stop
13
13
  @mixin assert-true(
14
14
  $assert,
15
- $description: ''
15
+ $description: null
16
16
  ) {
17
17
  $default: '"#{inspect($assert)}" should be truthy';
18
-
19
18
  @include _true-context('assert', $description or $default);
20
19
  @include _true-assert-results('assert-true', not not $assert, true);
21
20
  }
22
21
 
22
+
23
+
24
+ // Assert False
25
+ // ------------
23
26
  /// Assert that a parameter is `false`
24
27
  /// @access public
25
28
  /// @group testing
26
- /// @param {*} $assert - Assert
27
- /// @param {String} $description [''] - Assert description
28
- /// @require {mixin} _true-fail-details
29
- /// @require {mixin} _true-assert-start
30
- /// @require {mixin} _true-assert-stop
29
+ /// @param {*} $assert -
30
+ /// Assert
31
+ /// @param {String} $description [''] -
32
+ /// Assert description
31
33
  @mixin assert-false(
32
34
  $assert,
33
- $description: ''
35
+ $description: null
34
36
  ) {
35
37
  $default: '"#{inspect($assert)}" should be falsey';
36
-
37
38
  @include _true-context('assert', $description or $default);
38
- @include _true-assert-results('assert-false', $assert, false);
39
+ @include _true-assert-results('assert-false', not $assert, true);
39
40
  }
40
41
 
41
- /// /// Assert that two parameters are `equal`
42
+
43
+
44
+ // Assert Equal
45
+ // ------------
46
+ /// Assert that two parameters are `equal`
42
47
  /// @access public
43
48
  /// @group testing
44
- /// @param {*} $assert - Assert
45
- /// @param {*} $expected - Expected result
46
- /// @param {String} $description [''] - Assert description
47
- /// @require {mixin} _true-fail-details
48
- /// @require {mixin} _true-assert-start
49
- /// @require {mixin} _true-assert-stop
49
+ /// @param {*} $assert -
50
+ /// Assert
51
+ /// @param {*} $expected -
52
+ /// Expected result
53
+ /// @param {String} $description [''] -
54
+ /// Assert description
50
55
  @mixin assert-equal(
51
56
  $assert,
52
57
  $expected,
53
- $description: ''
58
+ $description: null
54
59
  ) {
55
60
  $default: '"#{inspect($assert)}" and "#{inspect($expected)}" should be equal';
56
-
57
61
  @include _true-context('assert', $description or $default);
58
62
  @include _true-assert-results('assert-equal', $assert, $expected);
59
63
  }
60
64
 
65
+
66
+ // Assert UnEqual
67
+ // --------------
61
68
  /// Assert that two parameters are `unequal`
62
69
  /// @access public
63
70
  /// @group testing
64
- /// @param {*} $assert - Assert
65
- /// @param {*} $expected - Expected result
66
- /// @param {String} $description [''] - Assert description
67
- /// @require {mixin} _true-fail-details
68
- /// @require {mixin} _true-assert-start
69
- /// @require {mixin} _true-assert-stop
71
+ /// @param {*} $assert -
72
+ /// Assert
73
+ /// @param {*} $expected -
74
+ /// Expected result
75
+ /// @param {String} $description [''] -
76
+ /// Assert description
70
77
  @mixin assert-unequal(
71
78
  $assert,
72
79
  $expected,
73
- $description: ''
80
+ $description: null
74
81
  ) {
75
82
  $default: '"#{inspect($assert)}" and "#{inspect($expected)}" should not be equal';
76
-
77
83
  @include _true-context('assert', $description or $default);
78
84
  @include _true-assert-results('assert-unequal', $assert, $expected, 'unequal');
79
85
  }
@@ -85,29 +91,31 @@
85
91
  /// Define a CSS-output assertion
86
92
  /// @access public
87
93
  /// @group testing
88
- /// @param {String} $description - Assert description
89
- /// @content Use `output()` and `expect()` mixins to define blocks for comparison
90
- /// @require {mixin} _true-assert-start
91
- /// @require {mixin} _true-assert-stop
92
- /// @require {function} _true-selector
94
+ /// @param {String} $description -
95
+ /// Assert description
96
+ /// @content Use `output()` and `expect()` mixins
97
+ /// to define blocks for comparison
93
98
  @mixin assert(
94
- $description: ''
99
+ $description: null
95
100
  ) {
96
101
  $default: _true-context('test') or 'CSS output should match expected output';
97
-
98
- @include _true-context('assert', $description);
102
+ @include _true-context('assert', $description or $default);
99
103
  @include _true-message(' ASSERT: #{$description} ', 'comments');
100
104
 
101
105
  @content;
102
106
 
103
- @include _true-update('output-to-css');
107
+ @include _true-update-test('output-to-css');
104
108
  @include _true-context-pop();
105
109
  @include _true-message(' END_ASSERT ', 'comments');
106
110
  }
107
111
 
108
112
 
113
+
114
+ // Output
115
+ // ------
109
116
  /// Describe the test content to be evaluated
110
- /// The output will be compared against the results of the `expect()` mixin.
117
+ /// The output will be compared against the results
118
+ /// of the `expect()` mixin.
111
119
  /// @access public
112
120
  /// @group testing
113
121
  @mixin output(
@@ -139,8 +147,12 @@
139
147
  }
140
148
 
141
149
 
150
+
151
+ // Expect
152
+ // ------
142
153
  /// Describe the output content to be expected.
143
- /// The output will be compared against the results of the `output()` mixin.
154
+ /// The output will be compared against the results
155
+ /// of the `output()` mixin.
144
156
  /// @access public
145
157
  /// @group testing
146
158
  @mixin expect(
@@ -160,9 +172,10 @@
160
172
  }
161
173
 
162
174
 
175
+
163
176
  // Assert Results
164
177
  // --------------
165
-
178
+ /// @access private
166
179
  @mixin _true-assert-results(
167
180
  $type,
168
181
  $assert,
@@ -197,6 +210,6 @@
197
210
  }
198
211
  }
199
212
 
200
- @include _true-update($result);
213
+ @include _true-update-test($result);
201
214
  @include _true-context-pop();
202
215
  }
@@ -0,0 +1,86 @@
1
+ // Context Management
2
+ // ==================
3
+
4
+
5
+
6
+ // Context [variable]
7
+ // ------------------
8
+ /// True current context
9
+ /// @access private
10
+ /// @type list
11
+ $_true-context: ();
12
+
13
+
14
+
15
+ // Context [mixin]
16
+ // ---------------
17
+ /// Update the current context for a given scope
18
+ /// @access private
19
+ /// @param {String} $scope - Either `module`, `test` or `assert`
20
+ /// @param {String} $name - Name of current scope
21
+ @mixin _true-context(
22
+ $scope,
23
+ $name
24
+ ) {
25
+ $_true-context: append($_true-context, ($scope, $name)) !global;
26
+ }
27
+
28
+
29
+
30
+ // Context Pop [mixin]
31
+ // -------------------
32
+ /// Remove the deepest context layer
33
+ /// @access private
34
+ @mixin _true-context-pop() {
35
+ $new: ();
36
+
37
+ @for $i from 1 to length($_true-context) {
38
+ $new: append($new, nth($_true-context, $i));
39
+ }
40
+
41
+ $_true-context: $new !global;
42
+ }
43
+
44
+
45
+
46
+ // Context [function]
47
+ // ------------------
48
+ /// Get information on current context for a given scope
49
+ /// @access private
50
+ /// @param {String} $scope
51
+ /// @return {String}
52
+ @function _true-context(
53
+ $scope
54
+ ) {
55
+ $value: null;
56
+
57
+ @each $entry-scope, $entry-value in $_true-context {
58
+ @if $entry-scope == $scope {
59
+ $value: $entry-value;
60
+ }
61
+ }
62
+
63
+ @return $value;
64
+ }
65
+
66
+
67
+
68
+ // Context All [function]
69
+ // ----------------------
70
+ /// Get list of context names for a given scope
71
+ /// @access private
72
+ /// @param {String} $scope
73
+ /// @return {List}
74
+ @function _true-context-all(
75
+ $scope
76
+ ) {
77
+ $list: ();
78
+
79
+ @each $entry-scope, $entry-value in $_true-context {
80
+ @if $entry-scope == $scope {
81
+ $list: append($list, $entry-value);
82
+ }
83
+ }
84
+
85
+ @return $list;
86
+ }
@@ -1,24 +1,30 @@
1
1
  // Messages
2
2
  // ========
3
3
 
4
+
5
+ // TNL
6
+ // ---
4
7
  /// New line helper
5
8
  /// @access private
6
- /// @group x_private
7
9
  /// @type String
8
- $-tnl: '\a ';
10
+ $_tnl: '\a ';
11
+
9
12
 
10
13
 
11
- /// Output a message to CSS comments, or command line terminal (via debug/warn)
14
+ // True Message
15
+ // ------------
16
+ /// Output a message to CSS comments,
17
+ /// or command line terminal (via debug/warn)
12
18
  /// @access private
13
- /// @group x_private
14
- /// @param {String} $message - Message to output
15
- /// @param {String} $output [comments] - Type of output, either `comments`, `terminal`, `debug` or `warn`
16
- /// @require {function} _true-str-split
19
+ /// @param {String} $message -
20
+ /// Message to output
21
+ /// @param {String} $output [comments] -
22
+ /// Type of output, either `comments`, `terminal`, `debug` or `warn`
17
23
  @mixin _true-message(
18
24
  $message,
19
25
  $output: 'comments'
20
26
  ) {
21
- $lines: _true-str-split($message, $-tnl);
27
+ $lines: _true-str-split($message, $_tnl);
22
28
  @if index($output, 'comments') {
23
29
  @each $line in $lines {
24
30
  /* #{$line} */
@@ -1,12 +1,14 @@
1
1
  // Test Module
2
2
  // ===========
3
3
 
4
+
5
+
6
+ // Test Module
7
+ // -----------
4
8
  /// Define a Test Module
5
9
  /// @access public
6
10
  /// @group testing
7
11
  /// @param {String} $name - Module name
8
- /// @require {mixin} _true-module-start
9
- /// @require {mixin} _true-module-stop
10
12
  /// @content Include all the tests that are part of this module
11
13
  @mixin test-module(
12
14
  $name
@@ -17,25 +19,23 @@
17
19
  }
18
20
 
19
21
 
20
- // Module Start (private)
21
- // ----------------------
22
22
 
23
+ // Module Start
24
+ // ------------
23
25
  /// Module start helper
24
26
  /// @access private
25
- /// @group x_private
26
27
  /// @param {String} $name - Module name
27
- /// @require {mixin} _true-context
28
- /// @require {mixin} _true-message
29
28
  @mixin _true-module-start(
30
29
  $name
31
30
  ) {
32
31
  @include _true-context(module, $name);
33
32
  $modules: _true-context-all('module');
34
- @include _true-message('# Module: #{_true-str-join($modules, ' :: ')}', 'comments');
33
+ $modules: _true-str-join($modules, ' :: ');
34
+ @include _true-message('# Module: #{$modules}', 'comments');
35
35
 
36
36
  $underline: '----------';
37
37
 
38
- @for $i from 1 through str-length($name) {
38
+ @for $i from 1 through str-length(inspect($modules)) {
39
39
  $underline: '#{$underline}-';
40
40
  }
41
41
 
@@ -43,14 +43,11 @@
43
43
  }
44
44
 
45
45
 
46
- // Module Stop (private)
47
- // ---------------------
48
46
 
47
+ // Module Stop
48
+ // -----------
49
49
  /// Module stop helper
50
50
  /// @access private
51
- /// @group x_private
52
- /// @require {mixin} _true-context
53
- /// @require {mixin} _true-message
54
51
  @mixin _true-module-stop {
55
52
  @include _true-context-pop();
56
53
  @include _true-message('', 'comments');
@@ -1,45 +1,102 @@
1
1
  // Results
2
2
  // =======
3
3
 
4
- /// Results map
4
+
5
+
6
+ // Report
7
+ // ------
8
+ /// Report results summary to CSS and/or command line
9
+ /// @access public
10
+ /// @group reporting
11
+ /// @param {Bool} $terminal [$true-terminal-output] -
12
+ /// Optionally output results to the terminal
13
+ /// @param {Bool} $fail-on-error [false] -
14
+ /// Optionally error out of the compiler if tests have failed
15
+ @mixin report(
16
+ $terminal: $true-terminal-output,
17
+ $fail-on-error: false
18
+ ) {
19
+ $message: _true-report-message('global', 'multiple');
20
+
21
+ $fail: map-get($_true-results, 'fail');
22
+ @if $fail-on-error and ($fail > 0) {
23
+ @error "#{$fail} tests failed."
24
+ }
25
+
26
+ @include _true-message('# SUMMARY ----------', 'comments');
27
+ @include _true-message($message, 'comments');
28
+ @include _true-message('--------------------', 'comments');
29
+
30
+ @if $terminal {
31
+ $message: _true-report-message('global', 'single');
32
+ @include _true-message($message, 'debug');
33
+ }
34
+ }
35
+
36
+
37
+
38
+ // Results
39
+ // -------
40
+ /// Global test-results map
5
41
  /// @access private
6
- /// @group x_private
7
42
  /// @type Map
8
43
  $_true-results: (
9
- run: 0,
10
- pass: 0,
11
- fail: 0,
12
- output-to-css: 0,
44
+ 'run': 0,
45
+ 'pass': 0,
46
+ 'fail': 0,
47
+ 'output-to-css': 0,
13
48
  );
14
49
 
15
50
 
51
+
52
+ // Test Fail
53
+ // ---------
54
+ // Local flags for tracking assertion results in a test
55
+ /// @access private
56
+ /// @type String
57
+ $_true-test-result: null;
58
+
59
+
60
+
61
+ // Update Test
62
+ // -----------
63
+ @mixin _true-update-test(
64
+ $result
65
+ ) {
66
+ @if ($result == 'fail') or ($_true-test-result == 'fail') {
67
+ $_true-test-result: 'fail' !global;
68
+ } @else if ($_true-test-result != 'output-to-css') {
69
+ $_true-test-result: $result !global;
70
+ }
71
+ }
72
+
73
+
74
+
16
75
  // Update
17
76
  // ------
18
-
19
77
  /// Update results
20
78
  /// @access private
21
- /// @group x_private
22
- /// @param {String} $result - Result (pass/fail/output-to-css)
23
- /// @require {function} _true-map-increment
24
- /// @require $_true-results
25
- @mixin _true-update($result) {
79
+ /// @param {String} $result -
80
+ /// Result (pass/fail/output-to-css)
81
+ @mixin _true-update(
82
+ $result
83
+ ) {
26
84
  $_true-results: _true-map-increment($_true-results, (
27
- run: 1,
85
+ 'run': 1,
28
86
  $result: 1,
29
87
  )) !global;
88
+ $_true-test-result: null !global;
30
89
  }
31
90
 
32
91
 
92
+
33
93
  // Report Message
34
94
  // --------------
35
-
36
95
  /// Report message
37
96
  /// @access private
38
- /// @group x_private
39
97
  /// @param {String} $scope [test] - Scope
40
98
  /// @param {String} $lines [single] - Lines
41
99
  /// @return {String} - Reported message
42
- /// @require {function} _true-get-results
43
100
  @function _true-report-message(
44
101
  $scope: 'test',
45
102
  $lines: 'single'
@@ -62,33 +119,9 @@ $_true-results: (
62
119
  $message: '#{$run} #{$items}, #{$pass} Passed, #{$fail} Failed';
63
120
  $message: if($output-to-css > 0, $message + ', #{$output-to-css} Output to CSS', $message);
64
121
  } @else {
65
- $message: '#{$run $items}:#{$-tnl} - #{$pass} Passed#{$-tnl} - #{$fail} Failed';
66
- $message: if($output-to-css > 0, $message + '#{$-tnl} - #{$output-to-css} Output to CSS', $message);
122
+ $message: '#{$run $items}:#{$_tnl} - #{$pass} Passed#{$_tnl} - #{$fail} Failed';
123
+ $message: if($output-to-css > 0, $message + '#{$_tnl} - #{$output-to-css} Output to CSS', $message);
67
124
  }
68
125
 
69
126
  @return $message;
70
127
  }
71
-
72
-
73
- // Report
74
- // ------
75
-
76
- /// Report results summary to CSS and/or command line
77
- /// @access public
78
- /// @group reporting
79
- /// @param {Bool} $terminal [$true-terminal-output] - Whether or not to use terminal output
80
- /// @require {function} _true-report-message
81
- /// @require {function} _true-message
82
- @mixin report(
83
- $terminal: $true-terminal-output
84
- ) {
85
- $message: _true-report-message('global', 'multiple');
86
- @include _true-message('# SUMMARY ----------', 'comments');
87
- @include _true-message($message, 'comments');
88
- @include _true-message('--------------------', 'comments');
89
-
90
- @if $terminal {
91
- $message: _true-report-message('global', 'single');
92
- @include _true-message($message, 'debug');
93
- }
94
- }