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
5 changes: 5 additions & 0 deletions intTests/test_set_base/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all: ;
clean:
sh ./test.sh clean

.PHONY: all clean
33 changes: 33 additions & 0 deletions intTests/test_set_base/test.log.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Loading file "test.saw"
== Anticipated failure message ==
Stack trace:
(builtin) in set_base
test.saw:11:8-11:18 in (callback)
(builtin) in fails
test.saw:11:1-11:18 (at top level)
set_base: unsupported base 0; value must be between 2 and 36

== Anticipated failure message ==
Stack trace:
(builtin) in set_base
test.saw:12:8-12:18 in (callback)
(builtin) in fails
test.saw:12:1-12:18 (at top level)
set_base: unsupported base 1; value must be between 2 and 36

== Anticipated failure message ==
Stack trace:
(builtin) in set_base
test.saw:13:8-13:19 in (callback)
(builtin) in fails
test.saw:13:1-13:19 (at top level)
set_base: unsupported base 37; value must be between 2 and 36

== Anticipated failure message ==
Stack trace:
(builtin) in set_base
test.saw:14:8-14:20 in (callback)
(builtin) in fails
test.saw:14:1-14:20 (at top level)
set_base: unsupported base 100; value must be between 2 and 36

14 changes: 14 additions & 0 deletions intTests/test_set_base/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Test that set_base works for valid bases and rejects invalid ones.

// Valid bases should succeed.
set_base 2;
set_base 8;
set_base 10;
set_base 16;
set_base 36;

// Invalid bases should fail.
fails (set_base 0);
fails (set_base 1);
fails (set_base 37);
fails (set_base 100);
1 change: 1 addition & 0 deletions intTests/test_set_base/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec ${TEST_SHELL:-bash} ../support/test-and-diff.sh "$@"
19 changes: 9 additions & 10 deletions saw-script/src/SAWScript/REPL/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,15 @@ searchExactCommandByPrefix prefix =
-- | Do tilde-expansion on filenames.
expandHome :: Text -> REPL FilePath
expandHome path =
case Text.uncons path of
Nothing -> pure ""
Just ('~', more) -> case Text.uncons more of
Just (c, more') | isPathSeparator c -> do
dir <- liftIO getHomeDirectory
return (dir </> Text.unpack more')
_ ->
pure $ Text.unpack path
Just _ ->
pure $ Text.unpack path
case Text.stripPrefix "~" path of
Nothing -> pure $ Text.unpack path
Just rest -> case Text.uncons rest of
Nothing -> liftIO getHomeDirectory
Just (c, more)
| isPathSeparator c -> do
dir <- liftIO getHomeDirectory
return (dir </> Text.unpack more)
| otherwise -> pure $ Text.unpack path

-- | Execute a REPL :-command.
executeReplCommand :: CommandDescr -> [Text] -> REPL ()
Expand Down
Loading