Created
April 3, 2013 10:03
-
-
Save sortega/5299935 to your computer and use it in GitHub Desktop.
Test for last gist
This file contains 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
(ns pyindent.test.core | |
(:use midje.sweet | |
pyindent.core)) | |
(fact "Tabs increment to the next multiple of 8" | |
(tabulate 0) => 8 | |
(tabulate 8) => 16 | |
(tabulate 7) => 8 | |
(tabulate 9) => 16) | |
(fact "Indent level is the number of spaces at the beginning of a line" | |
(indent-level "") => 0 | |
(indent-level "not indented") => 0 | |
(indent-level " some spaces") => 3 | |
(indent-level "\ta tab") => 8 | |
(indent-level "\t mixed spaces and tabs") => 10) | |
(fact "Check for non-empty lines" | |
(non-empty? "") => false | |
(non-empty? " \t") => false | |
(non-empty? "text") => true) | |
(fact "Convert a seq of lines into a seq of indent and dedents" | |
(indentations ["def main:" | |
" print 'hi!'"]) => [0 3] | |
(indentations [" first" | |
"second" | |
" third" | |
" forth"]) => [1 -1 4 -2] | |
(fact "Ignoring empty lines" | |
(indentations ["" | |
"def main:" | |
"" | |
" print 'hi!'"]) => [0 4])) | |
(fact "Drop until an element is found (included)" | |
(drop-upto 1 [1 2 3]) => [2 3] | |
(drop-upto 2 [1 2 3]) => [3] | |
(drop-upto 3 [1 2 3]) => [] | |
(drop-upto 9 [1 2 3]) => []) | |
(fact "Check for valid indentations" | |
(fact "Accept balanced dedents" | |
(valid-indentation? ["def main:" | |
" print 'hi!'" | |
" if foo:" | |
" foo++" | |
" return 0"]) => true) | |
(fact "The first line must have 0 indentation level" | |
(valid-indentation? [" def main:" | |
" print 'hi!'" | |
" if foo:" | |
" foo++" | |
" return 0"]) => false) | |
(fact "Dedents must match some indent" | |
(valid-indentation? ["def main:" | |
" print 'hi!'" | |
" if foo:" | |
" foo++" | |
" return 0"]) => false)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment