-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
expandvars
and respective tests. Added lit to pixi.toml, and `m…
…agic run` to pre-commit configuration. squash code a bit by using write add tests Cleanup with formatting and sign add missing newline Signed-off-by: Mikhail Tavarez <[email protected]>
- Loading branch information
1 parent
0b5df65
commit 0f28460
Showing
6 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ from .path import ( | |
dirname, | ||
exists, | ||
expanduser, | ||
expandvars, | ||
getsize, | ||
isdir, | ||
isfile, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# ===----------------------------------------------------------------------=== # | ||
# Copyright (c) 2024, Modular Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions: | ||
# https://llvm.org/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ===----------------------------------------------------------------------=== # | ||
# RUN: %mojo %s | ||
|
||
import os | ||
from os.path import expandvars | ||
from testing import assert_equal | ||
|
||
|
||
def test_expansion(): | ||
_ = os.setenv("TEST_VAR", "World") | ||
assert_equal(expandvars("Hello $TEST_VAR!"), "Hello World!") | ||
assert_equal(expandvars("漢字 $TEST_VAR🔥!"), "漢字 World🔥!") | ||
|
||
_ = os.setenv("UNICODE_TEST_VAR", "漢字🔥") | ||
assert_equal(expandvars("Hello $UNICODE_TEST_VAR!"), "Hello 漢字🔥!") | ||
assert_equal(expandvars("漢字 $UNICODE_TEST_VAR🔥!"), "漢字 漢字🔥🔥!") | ||
|
||
|
||
def test_braced_expansion(): | ||
_ = os.setenv("BRACE_VAR", "World") | ||
assert_equal(expandvars("Hello ${BRACE_VAR}!"), "Hello World!") | ||
assert_equal(expandvars("漢字 ${BRACE_VAR}🔥!"), "漢字 World🔥!") | ||
|
||
_ = os.setenv("UNICODE_BRACE_VAR", "漢字🔥") | ||
assert_equal(expandvars("Hello ${UNICODE_BRACE_VAR}!"), "Hello 漢字🔥!") | ||
assert_equal(expandvars("漢字 ${UNICODE_BRACE_VAR}🔥!"), "漢字 漢字🔥🔥!") | ||
|
||
|
||
def test_unset_expansion(): | ||
assert_equal(expandvars("Hello $NONEXISTENT_VAR!"), "Hello !") | ||
assert_equal(expandvars("漢字 ${NONEXISTENT_VAR}🔥!"), "漢字 🔥!") | ||
|
||
|
||
def main(): | ||
test_expansion() | ||
test_braced_expansion() | ||
test_unset_expansion() |