mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
New map_is_empty command
This commit is contained in:
parent
71a72103bf
commit
c2477cb4b1
|
@ -2,6 +2,7 @@
|
|||
|
||||
### v0.1.9
|
||||
|
||||
* New map_is_empty command.
|
||||
* New map_size command.
|
||||
* New map_remove command.
|
||||
* New is_map command.
|
||||
|
|
40
docs/sdk.md
40
docs/sdk.md
|
@ -24,6 +24,7 @@
|
|||
* [std::collections::IsMap (is_map)](#std__collections__IsMap)
|
||||
* [std::collections::Map (map)](#std__collections__Map)
|
||||
* [std::collections::MapGet (map_get)](#std__collections__MapGet)
|
||||
* [std::collections::MapIsEmpty (map_is_empty)](#std__collections__MapIsEmpty)
|
||||
* [std::collections::MapPut (map_put)](#std__collections__MapPut)
|
||||
* [std::collections::MapRemove (map_remove)](#std__collections__MapRemove)
|
||||
* [std::collections::MapSize (map_size)](#std__collections__MapSize)
|
||||
|
@ -1138,6 +1139,45 @@ release ${handle}
|
|||
#### Aliases:
|
||||
map_get
|
||||
|
||||
<a name="std__collections__MapIsEmpty"></a>
|
||||
## std::collections::MapIsEmpty
|
||||
|
||||
```sh
|
||||
var = map_is_empty handle
|
||||
```
|
||||
|
||||
Returns true if the provided map handle is an empty map.
|
||||
|
||||
#### Parameters
|
||||
|
||||
The map handle.
|
||||
|
||||
#### Return Value
|
||||
|
||||
True if the provided handle belongs to an empty map.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
handle = map
|
||||
map_put ${handle} key value
|
||||
empty = map_is_empty ${handle}
|
||||
```
|
||||
|
||||
|
||||
#### Source:
|
||||
|
||||
```sh
|
||||
|
||||
scope::map_is_empty::length = map_size ${scope::map_is_empty::argument::1}
|
||||
equals 0 ${scope::map_is_empty::length}
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
map_is_empty
|
||||
|
||||
<a name="std__collections__MapPut"></a>
|
||||
## std::collections::MapPut
|
||||
```sh
|
||||
|
|
21
duckscript_sdk/src/sdk/std/collections/map_is_empty/help.md
Normal file
21
duckscript_sdk/src/sdk/std/collections/map_is_empty/help.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
```sh
|
||||
var = map_is_empty handle
|
||||
```
|
||||
|
||||
Returns true if the provided map handle is an empty map.
|
||||
|
||||
#### Parameters
|
||||
|
||||
The map handle.
|
||||
|
||||
#### Return Value
|
||||
|
||||
True if the provided handle belongs to an empty map.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
handle = map
|
||||
map_put ${handle} key value
|
||||
empty = map_is_empty ${handle}
|
||||
```
|
22
duckscript_sdk/src/sdk/std/collections/map_is_empty/mod.rs
Executable file
22
duckscript_sdk/src/sdk/std/collections/map_is_empty/mod.rs
Executable file
|
@ -0,0 +1,22 @@
|
|||
use crate::types::command::create_alias_command;
|
||||
use crate::utils::pckg;
|
||||
use duckscript::types::command::Command;
|
||||
use duckscript::types::error::ScriptError;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "./mod_test.rs"]
|
||||
mod mod_test;
|
||||
|
||||
pub(crate) fn create(package: &str) -> Result<Box<dyn Command>, ScriptError> {
|
||||
let name = pckg::concat(package, "MapIsEmpty");
|
||||
let command = create_alias_command(
|
||||
name,
|
||||
vec!["map_is_empty".to_string()],
|
||||
include_str!("help.md").to_string(),
|
||||
"map_is_empty".to_string(),
|
||||
include_str!("script.ds").to_string(),
|
||||
1,
|
||||
)?;
|
||||
|
||||
Ok(Box::new(command))
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
use super::*;
|
||||
use crate::test;
|
||||
|
||||
#[test]
|
||||
fn common_functions() {
|
||||
test::test_common_command_functions(create("").unwrap());
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
scope::map_is_empty::length = map_size ${scope::map_is_empty::argument::1}
|
||||
equals 0 ${scope::map_is_empty::length}
|
|
@ -9,6 +9,7 @@ mod is_array;
|
|||
mod is_map;
|
||||
mod map;
|
||||
mod map_get;
|
||||
mod map_is_empty;
|
||||
mod map_put;
|
||||
mod map_remove;
|
||||
mod map_size;
|
||||
|
@ -36,6 +37,7 @@ pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptEr
|
|||
commands.set(is_map::create(&package))?;
|
||||
commands.set(map::create(&package))?;
|
||||
commands.set(map_get::create(&package))?;
|
||||
commands.set(map_is_empty::create(&package)?)?;
|
||||
commands.set(map_put::create(&package))?;
|
||||
commands.set(map_remove::create(&package))?;
|
||||
commands.set(map_size::create(&package))?;
|
||||
|
|
30
test/std/collections/array_is_empty_test.ds
Normal file
30
test/std/collections/array_is_empty_test.ds
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
fn test_size_empty
|
||||
handle = array
|
||||
|
||||
result = array_is_empty ${handle}
|
||||
assert ${result}
|
||||
|
||||
release ${handle}
|
||||
end
|
||||
|
||||
fn test_size_emptied
|
||||
handle = array
|
||||
|
||||
result = array_push ${handle} value
|
||||
assert_eq ${result} true
|
||||
array_pop ${handle}
|
||||
|
||||
result = array_is_empty ${handle}
|
||||
assert ${result}
|
||||
release ${handle}
|
||||
end
|
||||
|
||||
fn test_size_not_empty
|
||||
handle = array 1 2 3
|
||||
|
||||
result = array_is_empty ${handle}
|
||||
assert_false ${result}
|
||||
|
||||
release ${handle}
|
||||
end
|
35
test/std/collections/map_is_empty_test.ds
Normal file
35
test/std/collections/map_is_empty_test.ds
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
fn test_size_empty
|
||||
handle = map
|
||||
|
||||
result = map_is_empty ${handle}
|
||||
assert ${result}
|
||||
|
||||
release ${handle}
|
||||
end
|
||||
|
||||
fn test_size_emptied
|
||||
handle = map
|
||||
|
||||
result = map_put ${handle} key value
|
||||
assert_eq ${result} true
|
||||
map_remove ${handle} key
|
||||
|
||||
result = map_is_empty ${handle}
|
||||
assert ${result}
|
||||
release ${handle}
|
||||
end
|
||||
|
||||
fn test_size_not_empty
|
||||
handle = map
|
||||
|
||||
result = map_put ${handle} a 1
|
||||
result = map_put ${handle} b 2
|
||||
result = map_put ${handle} c 3
|
||||
result = map_put ${handle} a 4
|
||||
|
||||
result = map_is_empty ${handle}
|
||||
assert_false ${result}
|
||||
|
||||
release ${handle}
|
||||
end
|
Loading…
Reference in a new issue