diff options
author | Louis Pilfold <louis@lpil.uk> | 2021-07-18 13:42:19 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-07-18 13:42:19 +0100 |
commit | 6b449f10ee19c3012cfb8c33d9c687acd4d0d303 (patch) | |
tree | 79300b3c598169a88f392b0e3a5545efd7cc0e1c | |
parent | d62180206eabec96599b7e00002c211075732264 (diff) | |
download | gleam_stdlib-6b449f10ee19c3012cfb8c33d9c687acd4d0d303.tar.gz gleam_stdlib-6b449f10ee19c3012cfb8c33d9c687acd4d0d303.zip |
Remove os module
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/gleam/os.gleam | 69 | ||||
-rw-r--r-- | test/gleam/os_test.gleam | 49 |
3 files changed, 3 insertions, 119 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 88b43f4..2440c2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- The `os` module has been moved to the `gleam_os` library. - The `bool`, `order`, and `pair` modules now support JavaScript compilation. - The `map.update` function now uses `Option` rather than `Result`. - The `iterator` module gains the `fold_until` function. @@ -46,7 +47,8 @@ - The `bool` module gains the `nand`, `nor`, `exclusive_nor`, and `exclusive_or` functions. - The `bit_builder` module gains the `from_string_builder` function. - The `list` modules gains the `index_fold`, `permutations`, and `try_fold` functions. -- Breaking change in `queue.from_list`. The head element in the list becomes the first element in the queue. +- Breaking change in `queue.from_list`. The head element in the list becomes the + first element in the queue. - Fix `queue.pop_back` and `queue.pop_front` ## v0.12.0 - 2020-11-04 diff --git a/src/gleam/os.gleam b/src/gleam/os.gleam deleted file mode 100644 index af67e35..0000000 --- a/src/gleam/os.gleam +++ /dev/null @@ -1,69 +0,0 @@ -//// Function to interact with the host operating system. - -if erlang { - import gleam/list - import gleam/map.{Map} - import gleam/string - - // Internal type for erlang interop. - external type CharList - - external fn os_getenv() -> List(CharList) = - "os" "getenv" - - external fn os_putenv(key: CharList, value: CharList) -> Bool = - "os" "putenv" - - external fn os_unsetenv(key: CharList) -> Bool = - "os" "unsetenv" - - external fn char_list_to_string(CharList) -> String = - "unicode" "characters_to_binary" - - external fn string_to_char_list(String) -> CharList = - "unicode" "characters_to_list" - - /// Returns all environment variables set on the system. - pub fn get_env() -> Map(String, String) { - list.map( - os_getenv(), - fn(char_list) { - assert Ok(value) = - string.split_once(char_list_to_string(char_list), "=") - value - }, - ) - |> map.from_list() - } - - /// Sets an environment variable. - pub fn insert_env(key: String, value: String) -> Nil { - os_putenv(string_to_char_list(key), string_to_char_list(value)) - Nil - } - - /// Deletes an environment variable. - pub fn delete_env(key: String) -> Nil { - os_unsetenv(string_to_char_list(key)) - Nil - } - - pub type TimeUnit { - Second - Millisecond - Microsecond - Nanosecond - } - - /// Returns the current OS system time. - /// - /// https://erlang.org/doc/apps/erts/time_correction.html#OS_System_Time - pub external fn system_time(TimeUnit) -> Int = - "os" "system_time" - - /// Returns the current OS system time as a tuple of Ints - /// - /// http://erlang.org/doc/man/os.html#timestamp-0 - pub external fn erlang_timestamp() -> #(Int, Int, Int) = - "os" "timestamp" -} diff --git a/test/gleam/os_test.gleam b/test/gleam/os_test.gleam deleted file mode 100644 index b3d799d..0000000 --- a/test/gleam/os_test.gleam +++ /dev/null @@ -1,49 +0,0 @@ -if erlang { - import gleam/map - import gleam/os - import gleam/io - import gleam/should - - pub fn env_test() { - os.insert_env("GLEAM_TEST", "hello") - os.get_env() - |> map.get("GLEAM_TEST") - |> should.equal(Ok("hello")) - - os.delete_env("GLEAM_TEST") - os.get_env() - |> map.get("GLEAM_TEST") - |> should.equal(Error(Nil)) - } - - pub fn unicode_test() { - os.insert_env("GLEAM_UNICODE_TEST", "Iñtërnâtiônà£ißætiøn☃💩") - os.get_env() - |> map.get("GLEAM_UNICODE_TEST") - |> should.equal(Ok("Iñtërnâtiônà£ißætiøn☃💩")) - } - - pub fn system_time_test() { - let june_12_2020 = 1591966971 - { os.system_time(os.Second) > june_12_2020 } - |> should.equal(True) - { os.system_time(os.Second) < june_12_2020 * 1000 } - |> should.equal(True) - { os.system_time(os.Millisecond) > june_12_2020 * 1000 } - |> should.equal(True) - { os.system_time(os.Millisecond) < june_12_2020 * 1000000 } - |> should.equal(True) - } - - pub fn erlang_timestamp_test() { - // in microseconds - let june_12_2020 = 1591966971000000 - let #(mega_seconds, seconds, micro_seconds) = os.erlang_timestamp() - - let stamp_as_micro = - { mega_seconds * 1_000_000 + seconds } * 1_000_000 + micro_seconds - - { stamp_as_micro > june_12_2020 } - |> should.be_true() - } -} |