1
0

Refine command implementation; Add tests

This commit is contained in:
Jeff 2024-01-29 18:17:50 -05:00
parent df5cf93e58
commit 0752ebedf2
9 changed files with 23918 additions and 24635 deletions

View File

@ -0,0 +1,17 @@
async {
{
*echo 'Starting 1...'
*sleep 1
*echo 'Finished 1.'
}
{
*echo 'Starting 2...'
*sleep 2
*echo 'Finished 2.'
}
{
*echo 'Starting 3...'
*sleep 3
*echo 'Finished 3.'
}
}

View File

@ -206,7 +206,7 @@ impl StarshipPrompt {
let right_prompt = if let Ok(output) = &run_starship_right {
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
">".to_string()
"".to_string()
};
self.left = left_prompt;

20
tests/commands.rs Normal file
View File

@ -0,0 +1,20 @@
use dust_lang::{interpret, Value};
use std::fs::{remove_file, write};
#[test]
fn simple_command() {
assert_eq!(interpret("^echo hi"), Ok(Value::String("".to_string())))
}
#[test]
fn assign_command_output() {
write("target/test.txt", "123").unwrap();
assert_eq!(
interpret("x = ^cat target/test.txt; x"),
Ok(Value::String("123".to_string()))
);
remove_file("target/test.txt").unwrap();
}

View File

@ -2,7 +2,7 @@
Simple Command
================================================================================
*ls
^ls
--------------------------------------------------------------------------------
@ -16,7 +16,7 @@ Simple Command
Command Sequence
================================================================================
*less *ls
^less ^ls
--------------------------------------------------------------------------------
@ -34,7 +34,7 @@ Command Sequence
Command with Arguments
================================================================================
*ls --long -a
^ls --long -a
--------------------------------------------------------------------------------
@ -50,8 +50,8 @@ Command with Arguments
Command Sequence with Arguments
================================================================================
*cargo run -- -c "output('hi there')"
*ls --long -a
^cargo run -- -c "output('hi there')"
^ls --long -a
--------------------------------------------------------------------------------
@ -70,3 +70,126 @@ Command Sequence with Arguments
(command_text)
(command_argument)
(command_argument)))))
================================================================================
Command Sequence with Arguments
================================================================================
^cargo run -- -c "output('hi there')"
^ls --long -a
--------------------------------------------------------------------------------
(root
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument)
(command_argument)
(command_argument))))
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument)))))
================================================================================
Command Assignment
================================================================================
ls_output = ^ls --long -a;
cat_output = ^cat Cargo.toml;
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)))))))
================================================================================
Command with Semicolon
================================================================================
ls_output = ^ls --long -a; ls_output
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(statement
(expression
(identifier))))
================================================================================
Command with Semicolon
================================================================================
ls_output = ^ls --long -a; ls_output
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument)
(command_argument))))))
(statement
(expression
(identifier))))
================================================================================
Command with Quoted Semicolon
================================================================================
ls_output = ^echo ';'; ls_output
--------------------------------------------------------------------------------
(root
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(expression
(command
(command_text)
(command_argument))))))
(statement
(expression
(identifier))))

View File

@ -2,7 +2,7 @@
Simple Command Pipe
================================================================================
*ls | *less
^ls | ^less
--------------------------------------------------------------------------------

View File

@ -85,7 +85,7 @@ module.exports = grammar({
command: $ =>
prec.right(
seq(
'*',
'^',
$.command_text,
repeat($.command_argument),
),
@ -95,7 +95,7 @@ module.exports = grammar({
command_argument: $ =>
choice(
/[^*\s]+/,
/[^^|;\s]+/,
/("[^"]*?")|('[^']*?')|(`[^`]*?`)/,
),

View File

@ -233,7 +233,7 @@
"members": [
{
"type": "STRING",
"value": "*"
"value": "^"
},
{
"type": "SYMBOL",
@ -258,7 +258,7 @@
"members": [
{
"type": "PATTERN",
"value": "[^*\\s]+"
"value": "[^^|;\\s]+"
},
{
"type": "PATTERN",

View File

@ -885,6 +885,10 @@
"type": "]",
"named": false
},
{
"type": "^",
"named": false
},
{
"type": "any",
"named": false
@ -935,11 +939,11 @@
},
{
"type": "float",
"named": false
"named": true
},
{
"type": "float",
"named": true
"named": false
},
{
"type": "for",

File diff suppressed because it is too large Load Diff