-
Notifications
You must be signed in to change notification settings - Fork 54
Binary read support #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Binary read support #740
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9af86ed
Replace is fixed.
hulto 4077617
Update replace all
hulto fd1750a
Templates shouldn't have not-utf8 but if they do we'll replace with .
hulto 9fdab0c
Fix remote list
hulto 7e08f0c
Fixed read
hulto d810a33
Read binary works
hulto fd46714
Remove lint warn
hulto 7653e97
fix failing test
hulto 4beb40a
Merge branch 'main' into file-replace-support-utf-eight
hulto c0f4460
Merge branch 'main' into file-replace-support-utf-eight
hulto c0679a9
Fixing feedback
hulto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,34 +1,91 @@ | ||
| use anyhow::Result; | ||
| use anyhow::{Context, Result}; | ||
| use starlark::{eval::Evaluator, values::list::ListRef}; | ||
|
|
||
| pub fn list() -> Result<Vec<String>> { | ||
| pub fn list(starlark_eval: &Evaluator<'_, '_>) -> Result<Vec<String>> { | ||
| let mut res: Vec<String> = Vec::new(); | ||
| for file_path in super::Asset::iter() { | ||
| res.push(file_path.to_string()); | ||
| let remote_assets = starlark_eval.module().get("remote_assets"); | ||
|
|
||
| if let Some(assets) = remote_assets { | ||
| let tmp_list = ListRef::from_value(assets).context("`remote_assets` is not type list")?; | ||
| for asset_path in tmp_list.iter() { | ||
| let mut asset_path_string = asset_path.to_str(); | ||
| if let Some(local_asset_path_string) = asset_path_string.strip_prefix('"') { | ||
| asset_path_string = local_asset_path_string.to_string(); | ||
| } | ||
| if let Some(local_asset_path_string) = asset_path_string.strip_suffix('"') { | ||
| asset_path_string = local_asset_path_string.to_string(); | ||
| } | ||
| res.push(asset_path_string) | ||
| } | ||
| if res.len() > 0 { | ||
| return Ok(res); | ||
| } | ||
| } | ||
|
|
||
| for asset_path in super::Asset::iter() { | ||
| res.push(asset_path.to_string()); | ||
| } | ||
|
|
||
| Ok(res) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_assets_list() -> anyhow::Result<()> { | ||
| let res_all_embedded_files = list()?; | ||
|
|
||
| assert_eq!( | ||
| res_all_embedded_files, | ||
| [ | ||
| "exec_script/hello_world.bat", | ||
| "exec_script/hello_world.sh", | ||
| "exec_script/main.eldritch", | ||
| "exec_script/metadata.yml", | ||
| "print/main.eldritch", | ||
| "print/metadata.yml", | ||
| ] | ||
| ); | ||
|
|
||
| Ok(()) | ||
| use std::collections::HashMap; | ||
|
|
||
| use crate::runtime::Message; | ||
| use pb::eldritch::Tome; | ||
|
|
||
| macro_rules! test_cases { | ||
| ($($name:ident: $value:expr,)*) => { | ||
| $( | ||
| #[tokio::test] | ||
| async fn $name() { | ||
| let tc: TestCase = $value; | ||
|
|
||
| // Run Eldritch (until finished) | ||
| let mut runtime = crate::start(tc.id, tc.tome).await; | ||
| runtime.finish().await; | ||
|
|
||
| // Read Messages | ||
| let mut found = false; | ||
| for msg in runtime.messages() { | ||
| if let Message::ReportText(m) = msg { | ||
| assert_eq!(tc.id, m.id); | ||
| assert_eq!(tc.want_text, m.text); | ||
| found = true; | ||
| } | ||
| } | ||
| assert!(found); | ||
| } | ||
| )* | ||
| } | ||
| } | ||
|
|
||
| struct TestCase { | ||
| pub id: i64, | ||
| pub tome: Tome, | ||
| pub want_text: String, | ||
| } | ||
|
|
||
| test_cases! { | ||
| test_asset_list_remote: TestCase{ | ||
| id: 123, | ||
| tome: Tome{ | ||
| eldritch: String::from(r#"print(assets.list())"#), | ||
| parameters: HashMap::new(), | ||
| file_names: Vec::new(), | ||
| }, | ||
| want_text: String::from("[\"exec_script/hello_world.bat\", \"exec_script/hello_world.sh\", \"exec_script/main.eldritch\", \"exec_script/metadata.yml\", \"print/main.eldritch\", \"print/metadata.yml\"]\n"), | ||
| }, | ||
| test_asset_list_local: TestCase{ | ||
| id: 123, | ||
| tome: Tome{ | ||
| eldritch: String::from(r#"print(assets.list())"#), | ||
| parameters: HashMap::new(), | ||
| file_names: Vec::from(["remote_asset/just_a_remote_asset.txt".to_string()]), | ||
| }, | ||
| want_text: String::from("[\"remote_asset/just_a_remote_asset.txt\"]\n"), | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.