Last active
August 29, 2015 14:07
-
-
Save scottdavis/c0866101ff88b8b06b27 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.4.5) | |
// Compass (v1.0.1) | |
// ---- | |
// Sass BDD syntax proposal | |
// ======================== | |
// - based on [Jasmine](http://jasmine.github.io/2.0/introduction.html) | |
// - comparitor may be easier to parse with dashes e.g. "not-to-be" | |
// - simplest parsing would use commas as well e.g. "expect($foo, to equal, 1)" | |
// - describe/it/expect seems parallel to TDD module/test/assert | |
// - if so, True could impliment both syntaxes over the same logic | |
// Pseudo Code! | |
// ------------ | |
@function list-slice($list, $start: 1, $end: length($list), $sep:'comma') { | |
$result: null; | |
@if type-of($start) != number or type-of($end) != number { | |
@warn "Either $start or $end are not a number for `slice`."; | |
} | |
@else if $start > $end { | |
@warn "The start index has to be lesser than or equals to the end index for `slice`."; | |
} | |
@else if $start < 1 or $end < 1 { | |
@warn "List indexes must be non-zero integers for `slice`."; | |
} | |
@else if $start > length($list) { | |
@warn "List index is #{$start} but list is only #{length($list)} item long for `slice`."; | |
} | |
@else if $end > length($list) { | |
@warn "List index is #{$end} but list is only #{length($list)} item long for `slice`."; | |
} | |
@else { | |
$result: (); | |
@for $i from $start through $end { | |
$result: append($result, nth($list, $i), $sep); | |
} | |
} | |
@return $result; | |
} | |
@function be-matcher($list) { | |
/* be-matcher - #{$list} */ | |
@return "be-matcher"; | |
} | |
@function equal-matcher($list) { | |
/* equal-matcher - #{$list} */ | |
@return "equal-matcher"; | |
} | |
@function look-ahead($list, $current-index, $places-ahead) { | |
$index : $current-index - $places-ahead; | |
@if $index <= 0 { $index : 1; } | |
@return nth($list, $index); | |
} | |
@function scan-expects($list) { | |
@each $value in $list { | |
@if $value eq 'to' { | |
$index : index($list, $value); | |
$matcher : look-ahead($list, $index, 1); | |
@if function_exists("#{$matcher}-matcher") { | |
$remaining-args : list-slice($list, $index); | |
$foo : call("#{$matcher}-matcher", $list); | |
@return $foo; | |
} | |
} | |
} | |
@return "no matcher"; | |
} | |
@mixin describe($desc){ | |
/* | |
/* #{$desc} */ | |
@content | |
} | |
@mixin it($desc){ | |
/* - #{$desc} */ | |
@content | |
} | |
@mixin expect($test){ | |
/* -- EXPECT: #{$test} */ | |
$foo : scan-expects($test); | |
/* --Matcher: #{$foo} */ | |
@content | |
} | |
// USAGE | |
// ----- | |
@include describe("A suite") { | |
@include it("contains spec with an expectation") { | |
@include expect(true to be true); | |
} | |
} | |
@include describe("The 'toBe' matcher compares with ===") { | |
@include it("and has a positive case") { | |
@include expect(true to be true); | |
} | |
@include it("and can have a negative case") { | |
@include expect(false not to be true); | |
} | |
} | |
@include describe("A spec") { | |
@include it("is just a function, so it can contain any code") { | |
$foo: 0; | |
$foo: $foo + 1; | |
@include expect($foo to equal 1); | |
} | |
@include it("can have more than one expectation") { | |
$foo: 0; | |
$foo: $foo + 1; | |
@include expect($foo to equal 1); | |
@include expect(true to equal true); | |
@include expect(12 to be gte 9); | |
@include expect(12 to be '>=' 9); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
/* A suite */ | |
/* - contains spec with an expectation */ | |
/* -- EXPECT: true to be true */ | |
/* --Matcher: no matcher */ | |
/* | |
/* The 'toBe' matcher compares with === */ | |
/* - and has a positive case */ | |
/* -- EXPECT: true to be true */ | |
/* --Matcher: no matcher */ | |
/* - and can have a negative case */ | |
/* -- EXPECT: false false be true */ | |
/* --Matcher: be-matcher */ | |
/* | |
/* A spec */ | |
/* - is just a function, so it can contain any code */ | |
/* -- EXPECT: 1 to equal 1 */ | |
/* --Matcher: no matcher */ | |
/* - can have more than one expectation */ | |
/* -- EXPECT: 1 to equal 1 */ | |
/* --Matcher: no matcher */ | |
/* -- EXPECT: true to equal true */ | |
/* --Matcher: no matcher */ | |
/* -- EXPECT: 12 to be gte 9 */ | |
/* --Matcher: be-matcher */ | |
/* -- EXPECT: 12 to be >= 9 */ | |
/* --Matcher: be-matcher */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment