;; This Source Code Form is subject to the terms of the Mozilla Public ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; (bjosh editor): when Enter runs a line, and completion. ;; ;; bjo test tests/editor.bjo (import (std prelude)) (import (std simpletest)) (import (bjoterm line)) (import (bjosh editor)) (import/extern (temp-dir (: System.IO.Path.GetTempPath (-> string))) (process-id (: System.Environment.ProcessId int #:get #:no-raise))) (defun (main args) (expect "a whole line runs" (input-done? "ls -l") #t) (expect "an open quote waits" (input-done? "echo 'abc") #f) (expect "an open double quote waits" (input-done? "echo \"abc") #f) (expect "| at the end waits" (input-done? "ls |") #f) (expect "&& at the end waits" (input-done? "make &&") #f) (expect "\\ at the end waits" (input-done? "echo a \\") #f) (expect "\\\\ at the end runs" (input-done? "echo a \\\\") #t) (expect "a line that is not supported runs, to show the error" (input-done? "if true") #t) (expect "two lines" (input-done? "echo 'a\nb'") #t) (expect "the word before the cursor" (word-start "ls -l fo") 6) (expect "after an operator" (word-start "a|b") 2) (expect "the first word is a command" (command-position? "ls" 0) #t) (expect "the second is not" (command-position? "ls -l" 3) #f) (expect "after | it is" (command-position? "a | b" 4) #t) (expect "after && it is" (command-position? "a && b" 5) #t) (expect "spaces are quoted" (quote-name "a b") "a\\ b") (expect "and $" (quote-name "$x") "\\$x") (def dir (path-combine (temp-dir) (str "bjosh-editor-" (int->string process-id)))) (ignore (directory-create (path-combine dir "abd"))) (ignore (file-write-text (path-combine dir "abc.txt") "")) (ignore (file-write-text (path-combine dir "a b") "")) (ignore (file-write-text (path-combine dir ".hidden") "")) (ignore (file-write-text (path-combine dir "abd/inner") "")) (def here (current-directory)) (set-current-directory! dir) (expect "files and directories" (file-candidates "ab") ["abc.txt " "abd/"]) (expect "not hidden files" (file-candidates "") ["a\\ b " "abc.txt " "abd/"]) (expect "hidden files for a dot" (file-candidates ".h") [".hidden "]) (expect "in a directory" (file-candidates "abd/i") ["abd/inner "]) (expect "the second word completes files" (record-ref (complete "cat ab") candidates) ["abc.txt " "abd/"]) (expect "the first word completes commands" (any? (fun (c) (= c "jobs ")) (record-ref (complete "jo") candidates)) #t) (expect "a first word with a / completes files" (record-ref (complete "./ab") candidates) ["./abc.txt " "./abd/"]) (set-current-directory! here) (ignore (directory-delete-tree dir)) 0)