Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
382 changes: 191 additions & 191 deletions styl/true/_context.styl
Original file line number Diff line number Diff line change
@@ -1,191 +1,191 @@
// unwrap-list($list)
//
// **[private:{list}]** Transforms a wrapped list into a unwrapped one
//
// Weight: 0
//
// $list - **{list}** ***List to be unwrapped***
//
// Styleguide Functions.unwrap-list
use('lib/unwrap-list.js');

// $_true-context = { buffer }
//
// **[private]** Stores the current module/test/assertion context stack
//
// Weight: 0
//
// $buffer = () - **{list}** ***List to use as buffer for parsing***
//
// Styleguide Variables.$_true-context
$_true-context = {
buffer: ()
};

// _true-context-mixin($scope, $name)
//
// **[private:{void}]** Update the current context for a given scope
//
// Weight: 0
//
// $scope - **{string}** ***Either `module`, `test` or `assert`***
// $name - **{string}** ***Name or description of the current scope***
//
// Styleguide Functions._true-context-mixin
_true-context-mixin($scope, $name) {
push($_true-context.buffer, '%s|%s' % (unquote($scope) unquote($name)));

$_true-context.buffer = unwrap-list($_true-context.buffer);
}

// _true-context-pop($type)
//
// **[private:{void}]** Remove the deepest context layer from `$_true-context.buffer`
//
// Weight: 0
//
// Styleguide Functions._true-output-pop
_true-context-pop($type = null) {
$new = ();

if ($type == null) {
for $i in 0 .. (length($_true-context.buffer) - 1) {
push($new, $_true-context.buffer[$i]);
}

$_true-context.buffer = $new;
} else {
$_true-context.buffer = ();
}
}

$_true-output-context = {
value: ()
};

// _true-output-context($new, $context)
//
// **[private:{void}]** Add `assert`, `output`, `expect`, or `contains` context to an output test, or check to make sure they all exist before resetting the context.
//
// Weight: 0
//
// $new - **{'assert'|'output'|'expect'|'contains'|null}** ***Add a new `assert`, `output`, `expect`, or `contains` layer to the context of an output-test, or use `null` to check that all context is properly formed and then reset it at the end of a test***
// $context = $_true-output-context.value - **{list}** ***The current output context***
//
// Styleguide Functions._true-output-context
_true-output-context($new, $context = $_true-output-context.value) {
$valid = 'assert' 'expect' 'output' 'contains';

$_true-output-context.value = _true-validate-output-context($new, $context);
}

// _true-validate-output-context($new, $context)
//
// **[private:{string}]** Validate the new context, and return an updated context value
//
// Weight: 0
//
// $new - **{'assert'|'output'|'expect'|'contains'|null}** ***Add a new `assert`, `output`, `expect`, or `contains` layer to the context of an output-test, or use `null` to check that all context is properly formed and then reset it at the end of a test***
// $context = $_true-output-context.value - **{list}** ***The current output context***
//
// Styleguide Functions._true-validate-output-context
_true-validate-output-context($new, $context = $_true-output-context.value) {
$valid = 'assert' 'expect' 'output' 'contains';

$validIndex = index($valid, $new);
$contextIndex = index($context, $new);
$assertIndex = index($context, 'assert')

if ($new && $validIndex == null || $validIndex < 0 ) {
$error = $new + ' is not a valid context for output tests: ' + $valid;

return _true-error($error, 'output-context');
} else if ($contextIndex != null && $contextIndex >= 0 ) {
if ($new == 'assert') {
$error = 'The `assert()` mixin can not contain another `assert()`';

return _true-error($error, 'output-context');
}

$error = 'The `%s()` mixin must only be used once per `assert()`' % unquote($new);

return _true-error($error, 'output-context');
} else if ($new) {
$is-sub = index('expect' 'output' 'contains', $new);
$is-sub = $is-sub != null && $is-sub >= 0;

// if ($is-sub && !($assertIndex != null && $assertIndex >= 0)) {
// $error = 'The `assert()` wrapper is required';

// return _true-error($error, 'output-context');
// }

push($context, $new);
return $context
}

$length = length($context);
$has-expect = index($context, 'expect') || index($context, 'contains');
$has-both = index($context, 'output') && $has-expect;

// if ($length != 3 || !$has-both) {
// $required = 'one `output()`, and one `expect()` or `contains()`';
// $error = 'Each `assert()` must contain %s' % $required;

// return _true-error($error, 'output-context');
// }

return ();
}

// _true-context($scope)
//
// **[private:{string}]** Get information on current context for a given scope
//
// Weight: 0
//
// $scope - **{string}** ***Scope to search for***
//
// Styleguide Functions._true-context
_true-context($scope) {
$value = null;

for $entry in ($_true-context.buffer) {
$entries = split('|', $entry);

$entry-scope = $entries[0];
$entry-value = $entries[1];
}

if ($entry-scope == $scope) {
$value = $entry-value;
}

return $value;
}

// _true-context-all($scope)
//
// **[private:{list}]** Get list of context names for a given scope
//
// Weight: 0
//
// $scope - **{string}** ***Scope to search for***
//
// Styleguide Functions._true-context-all
_true-context-all($scope) {
$list = ();

for $entry in ($_true-context.buffer) {
$entries = split('|', $entry);

$entry-scope = $entries[0];
$entry-value = $entries[1];

if ($entry-scope == $scope) {
push($list, $entry-value);
}
}

return $list;
}
// unwrap-list($list)
//
// **[private:{list}]** Transforms a wrapped list into a unwrapped one
//
// Weight: 0
//
// $list - **{list}** ***List to be unwrapped***
//
// Styleguide Functions.unwrap-list
use('../../lib/unwrap-list.js');
// $_true-context = { buffer }
//
// **[private]** Stores the current module/test/assertion context stack
//
// Weight: 0
//
// $buffer = () - **{list}** ***List to use as buffer for parsing***
//
// Styleguide Variables.$_true-context
$_true-context = {
buffer: ()
};
// _true-context-mixin($scope, $name)
//
// **[private:{void}]** Update the current context for a given scope
//
// Weight: 0
//
// $scope - **{string}** ***Either `module`, `test` or `assert`***
// $name - **{string}** ***Name or description of the current scope***
//
// Styleguide Functions._true-context-mixin
_true-context-mixin($scope, $name) {
push($_true-context.buffer, '%s|%s' % (unquote($scope) unquote($name)));
$_true-context.buffer = unwrap-list($_true-context.buffer);
}
// _true-context-pop($type)
//
// **[private:{void}]** Remove the deepest context layer from `$_true-context.buffer`
//
// Weight: 0
//
// Styleguide Functions._true-output-pop
_true-context-pop($type = null) {
$new = ();
if ($type == null) {
for $i in 0 .. (length($_true-context.buffer) - 1) {
push($new, $_true-context.buffer[$i]);
}
$_true-context.buffer = $new;
} else {
$_true-context.buffer = ();
}
}
$_true-output-context = {
value: ()
};
// _true-output-context($new, $context)
//
// **[private:{void}]** Add `assert`, `output`, `expect`, or `contains` context to an output test, or check to make sure they all exist before resetting the context.
//
// Weight: 0
//
// $new - **{'assert'|'output'|'expect'|'contains'|null}** ***Add a new `assert`, `output`, `expect`, or `contains` layer to the context of an output-test, or use `null` to check that all context is properly formed and then reset it at the end of a test***
// $context = $_true-output-context.value - **{list}** ***The current output context***
//
// Styleguide Functions._true-output-context
_true-output-context($new, $context = $_true-output-context.value) {
$valid = 'assert' 'expect' 'output' 'contains';
$_true-output-context.value = _true-validate-output-context($new, $context);
}
// _true-validate-output-context($new, $context)
//
// **[private:{string}]** Validate the new context, and return an updated context value
//
// Weight: 0
//
// $new - **{'assert'|'output'|'expect'|'contains'|null}** ***Add a new `assert`, `output`, `expect`, or `contains` layer to the context of an output-test, or use `null` to check that all context is properly formed and then reset it at the end of a test***
// $context = $_true-output-context.value - **{list}** ***The current output context***
//
// Styleguide Functions._true-validate-output-context
_true-validate-output-context($new, $context = $_true-output-context.value) {
$valid = 'assert' 'expect' 'output' 'contains';
$validIndex = index($valid, $new);
$contextIndex = index($context, $new);
$assertIndex = index($context, 'assert')
if ($new && $validIndex == null || $validIndex < 0 ) {
$error = $new + ' is not a valid context for output tests: ' + $valid;
return _true-error($error, 'output-context');
} else if ($contextIndex != null && $contextIndex >= 0 ) {
if ($new == 'assert') {
$error = 'The `assert()` mixin can not contain another `assert()`';
return _true-error($error, 'output-context');
}
$error = 'The `%s()` mixin must only be used once per `assert()`' % unquote($new);
return _true-error($error, 'output-context');
} else if ($new) {
$is-sub = index('expect' 'output' 'contains', $new);
$is-sub = $is-sub != null && $is-sub >= 0;
// if ($is-sub && !($assertIndex != null && $assertIndex >= 0)) {
// $error = 'The `assert()` wrapper is required';
// return _true-error($error, 'output-context');
// }
push($context, $new);
return $context
}
$length = length($context);
$has-expect = index($context, 'expect') || index($context, 'contains');
$has-both = index($context, 'output') && $has-expect;
// if ($length != 3 || !$has-both) {
// $required = 'one `output()`, and one `expect()` or `contains()`';
// $error = 'Each `assert()` must contain %s' % $required;
// return _true-error($error, 'output-context');
// }
return ();
}
// _true-context($scope)
//
// **[private:{string}]** Get information on current context for a given scope
//
// Weight: 0
//
// $scope - **{string}** ***Scope to search for***
//
// Styleguide Functions._true-context
_true-context($scope) {
$value = null;
for $entry in ($_true-context.buffer) {
$entries = split('|', $entry);
$entry-scope = $entries[0];
$entry-value = $entries[1];
}
if ($entry-scope == $scope) {
$value = $entry-value;
}
return $value;
}
// _true-context-all($scope)
//
// **[private:{list}]** Get list of context names for a given scope
//
// Weight: 0
//
// $scope - **{string}** ***Scope to search for***
//
// Styleguide Functions._true-context-all
_true-context-all($scope) {
$list = ();
for $entry in ($_true-context.buffer) {
$entries = split('|', $entry);
$entry-scope = $entries[0];
$entry-value = $entries[1];
if ($entry-scope == $scope) {
push($list, $entry-value);
}
}
return $list;
}
Loading