Skip to content

Commit

Permalink
Pass all unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Oct 5, 2024
1 parent e3eb05a commit 69d57b9
Show file tree
Hide file tree
Showing 13 changed files with 622 additions and 129 deletions.
16 changes: 0 additions & 16 deletions packages/apis/src/decomposed_defs/email_addr_with_name.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/apis/src/decomposed_defs/from_addr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[A-Za-z0-9.\\-]+"
"regex_def": "[^<>]+"
},
{
"is_public": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/decomposed_defs/to_addr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"is_public": true,
"regex_def": "[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+@[a-zA-Z0-9.\\-]+"
"regex_def": "[^<>]+"
},
{
"is_public": false,
Expand Down
40 changes: 20 additions & 20 deletions packages/apis/src/extract_substrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ pub fn extract_email_domain_idxes(
extract_substr_idxes(input_str, &serde_json::from_str(regex_config).unwrap())
}

pub fn extract_email_addr_with_name_idxes(
input_str: &str,
) -> Result<Vec<(usize, usize)>, ExtractSubstrssError> {
let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json");
extract_substr_idxes(input_str, &serde_json::from_str(regex_config).unwrap())
}
// pub fn extract_email_addr_with_name_idxes(
// input_str: &str,
// ) -> Result<Vec<(usize, usize)>, ExtractSubstrssError> {
// let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json");
// extract_substr_idxes(input_str, &serde_json::from_str(regex_config).unwrap())
// }

pub fn extract_from_all_idxes(
input_str: &str,
Expand Down Expand Up @@ -166,20 +166,20 @@ mod test {
assert_eq!(idxes, vec![(17, 38)]);
}

#[test]
fn test_email_addr_with_name_valid1() {
let input_str = "from:[email protected] <[email protected]>";
let idxes = extract_email_addr_with_name_idxes(input_str).unwrap();
assert_eq!(idxes, vec![(18, 39)]);
}

#[test]
fn test_email_addr_with_name_valid2() {
// "末神 奏宙" has 13 bytes.
let input_str = "from:\"末神 奏宙\" <[email protected]>";
let idxes = extract_email_addr_with_name_idxes(input_str).unwrap();
assert_eq!(idxes, vec![(22, 43)]);
}
// #[test]
// fn test_email_addr_with_name_valid1() {
// let input_str = "from:[email protected] <[email protected]>";
// let idxes = extract_email_addr_with_name_idxes(input_str).unwrap();
// assert_eq!(idxes, vec![(18, 39)]);
// }

// #[test]
// fn test_email_addr_with_name_valid2() {
// // "末神 奏宙" has 13 bytes.
// let input_str = "from:\"末神 奏宙\" <[email protected]>";
// let idxes = extract_email_addr_with_name_idxes(input_str).unwrap();
// assert_eq!(idxes, vec![(22, 43)]);
// }

#[test]
fn test_email_from_all_valid() {
Expand Down
12 changes: 6 additions & 6 deletions packages/apis/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ pub fn extractEmailDomainIdxes(inputStr: &str) -> Array {
extractSubstrIdxes(inputStr, JsValue::from_str(regex_config))
}

#[wasm_bindgen]
#[allow(non_snake_case)]
pub fn extractEmailAddrWithNameIdxes(inputStr: &str) -> Array {
let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json");
extractSubstrIdxes(inputStr, JsValue::from_str(regex_config))
}
// #[wasm_bindgen]
// #[allow(non_snake_case)]
// pub fn extractEmailAddrWithNameIdxes(inputStr: &str) -> Array {
// let regex_config = include_str!("./decomposed_defs/email_addr_with_name.json");
// extractSubstrIdxes(inputStr, JsValue::from_str(regex_config))
// }

#[wasm_bindgen]
#[allow(non_snake_case)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma circom 2.1.5;

include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom";
include "./reversed_email_addr_with_name_regex.circom";
include "./reversed_bracket_regex.circom";

template EmailAddrWithNameRegex(msg_bytes) {
signal input msg[msg_bytes];
Expand All @@ -13,7 +13,7 @@ template EmailAddrWithNameRegex(msg_bytes) {
for(var i=0; i<msg_bytes; i++) {
reversed_msg[i] <== msg[msg_bytes - i - 1];
}
(out, reversed_reveal0) <== ReversedEmailAddrWithNameRegex(msg_bytes)(reversed_msg);
(out, reversed_reveal0) <== ReversedBracketRegex(msg_bytes)(reversed_msg);
for(var i=0; i<msg_bytes; i++) {
reveal0[i] <== reversed_reveal0[msg_bytes - i - 1];
}
Expand Down
20 changes: 0 additions & 20 deletions packages/circom/circuits/common/from_addr.json

This file was deleted.

8 changes: 4 additions & 4 deletions packages/circom/circuits/common/from_addr_regex.circom
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma circom 2.1.5;

include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom";
include "@zk-email/zk-regex-circom/circuits/common/from_all_regex.circom";
include "@zk-email/zk-regex-circom/circuits/common/email_addr_regex.circom";
include "@zk-email/zk-regex-circom/circuits/common/email_addr_with_name_regex.circom";
include "../regex_helpers.circom";
include "./from_all_regex.circom";
include "./email_addr_regex.circom";
include "./email_addr_with_name_regex.circom";


template FromAddrRegex(msg_bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"is_public": true,
"regex_def": "[a-zA-Z0-9.\\-]+@[A-Za-z0-9!#$%&'*+=?\\-\\^_`{|}~./@]+"
"regex_def": "[^<>]+"
},
{
"is_public": false,
Expand Down
Loading

0 comments on commit 69d57b9

Please sign in to comment.