|
1 |
| -pub const GBNF_GRAMMAR: &str = "TODO"; |
| 1 | +pub const ENHANCE_AUTO: &str = include_str!("../assets/enhance-auto.gbnf"); |
| 2 | + |
| 3 | +#[cfg(test)] |
| 4 | +mod tests { |
| 5 | + use super::*; |
| 6 | + use indoc::indoc; |
| 7 | + |
| 8 | + #[test] |
| 9 | + fn test_1() { |
| 10 | + let gbnf = gbnf_validator::Validator::new().unwrap(); |
| 11 | + let input_1 = "<headers>\n- Objective\n- Key Takeaways\n- Importance of Complementary Skills\n- Benefits of Using Online Resources\n- Advice for Undergrad Students\n</headers># Objective\n\n- **Search is the Best Way to Find Answers**: The speaker emphasizes the importance of utilizing online resources like Google to find answers to questions.\n- **Value in Complementary Skills**: The speaker highlights the need to acquire complementary skills to traditional research methods.\n\n# Key Takeaways\n\n- **Complementary skills include both traditional research and online resource utilization**: The speaker suggests that skills like using a blank sheet of paper with no Internet and effective Google searching are essential.\n- **Online resources can help find pre-solved problems**: The speaker advises investing time in finding existing resources and communities that have already solved problems.\n\n# Importance of Complementary Skills\n\n- **Traditional research is just the starting point**: The speaker suggests that traditional research methods are just the beginning and should be complemented with other skills.\n- **Effective use of online resources can save time and effort**: The speaker highlights the benefits of utilizing online resources in research and problem-solving.\n\n# Benefits of Using Online Resources\n\n- **Access to knowledge from experts and communities**: The speaker suggests that online resources provide access to knowledge and expertise from experienced individuals.\n- **Time-saving and efficient**: The speaker emphasizes the benefits of finding pre-solved problems through online resources.\n\n# Advice for Undergrad Students\n\n- **Start by searching online**: The speaker advises undergrad students to start by searching online for answers to questions and exploring different resources.\n- **Be open to finding existing solutions**: The speaker emphasizes the importance of being open to finding pre-solved problems and leveraging existing resources.\n\n"; |
| 12 | + let input_2 = indoc! {" |
| 13 | + <headers> |
| 14 | + - Objective |
| 15 | + - Key Takeaways |
| 16 | + - Importance of Complementary Skills |
| 17 | + - Benefits of Using Online Resources |
| 18 | + - Advice for Undergrad Students |
| 19 | + </headers># Objective |
| 20 | + |
| 21 | + - **Search is the Best Way to Find Answers**: The speaker emphasizes the importance of utilizing online resources like Google to find answers to questions. |
| 22 | + - **Value in Complementary Skills**: The speaker highlights the need to acquire complementary skills to traditional research methods. |
| 23 | + |
| 24 | + # Key Takeaways |
| 25 | + |
| 26 | + - **Complementary skills include both traditional research and online resource utilization**: The speaker suggests that skills like using a blank sheet of paper with no Internet and effective Google searching are essential. |
| 27 | + - **Online resources can help find pre-solved problems**: The speaker advises investing time in finding existing resources and communities that have already solved problems. |
| 28 | + |
| 29 | + # Importance of Complementary Skills |
| 30 | + |
| 31 | + - **Traditional research is just the starting point**: The speaker suggests that traditional research methods are just the beginning and should be complemented with other skills. |
| 32 | + - **Effective use of online resources can save time and effort**: The speaker highlights the benefits of utilizing online resources in research and problem-solving. |
| 33 | + |
| 34 | + # Benefits of Using Online Resources |
| 35 | + |
| 36 | + - **Access to knowledge from experts and communities**: The speaker suggests that online resources provide access to knowledge and expertise from experienced individuals. |
| 37 | + - **Time-saving and efficient**: The speaker emphasizes the benefits of finding pre-solved problems through online resources. |
| 38 | + |
| 39 | + # Advice for Undergrad Students |
| 40 | + |
| 41 | + - **Start by searching online**: The speaker advises undergrad students to start by searching online for answers to questions and exploring different resources. |
| 42 | + - **Be open to finding existing solutions**: The speaker emphasizes the importance of being open to finding pre-solved problems and leveraging existing resources. |
| 43 | + |
| 44 | + "}; |
| 45 | + |
| 46 | + assert_eq!(input_1, input_2); |
| 47 | + assert!(gbnf.validate(ENHANCE_AUTO, input_1).unwrap()); |
| 48 | + } |
| 49 | + |
| 50 | + #[test] |
| 51 | + fn test_2() { |
| 52 | + let gbnf = gbnf_validator::Validator::new().unwrap(); |
| 53 | + let input = indoc! {" |
| 54 | + <headers> |
| 55 | + - Objective |
| 56 | + - Key Takeaways |
| 57 | + - Importance of Complementary Skills |
| 58 | + - Benefits of Using Online Resources |
| 59 | + - Advice for Undergrad Students |
| 60 | + </headers># Objective |
| 61 | + |
| 62 | + - **Search is the Best Way to Find Answers**: The speaker emphasizes the importance of utilizing online resources like Google to find answers to questions. |
| 63 | + - **Value in Complementary Skills**: The speaker highlights the need to acquire complementary skills to traditional research methods. |
| 64 | + |
| 65 | + # Key Takeaways |
| 66 | + |
| 67 | + - **Complementary skills include both traditional research and online resource utilization**: The speaker suggests that skills like using a blank sheet of paper with no Internet and effective Google searching are essential. |
| 68 | + - **Online resources can help find pre-solved problems**: The speaker advises investing time in finding existing resources and communities that have already solved problems. |
| 69 | + |
| 70 | + # Importance of Complementary Skills |
| 71 | + |
| 72 | + - **Traditional research is just the starting point**: The speaker suggests that traditional research methods are just the beginning and should be complemented with other skills. |
| 73 | + - **Effective use of online resources can save time and effort**: The speaker highlights the benefits of utilizing online resources in research and problem-solving. |
| 74 | + |
| 75 | + # Benefits of Using Online Resources |
| 76 | + |
| 77 | + - **Access to knowledge from experts and communities**: The speaker suggests that online resources provide access to knowledge and expertise from experienced individuals. |
| 78 | + - **Time-saving and efficient**: The speaker emphasizes the benefits of finding pre-solved problems through online resources. |
| 79 | + |
| 80 | + # Advice for Undergrad Students |
| 81 | + |
| 82 | + - **Start by searching online**: The speaker advises undergrad students to start by searching online for answers to questions and exploring different resources. |
| 83 | + - **Be open to finding existing solutions**: The speaker emphasizes the importance of being open to finding pre-solved problems and leveraging existing resources. |
| 84 | + - **Follow on X**: [Thank you](https://x.com/yujonglee). |
| 85 | + |
| 86 | + "}; |
| 87 | + |
| 88 | + assert!(gbnf.validate(ENHANCE_AUTO, input).unwrap()); |
| 89 | + } |
| 90 | + |
| 91 | + #[allow(dead_code)] |
| 92 | + fn debug_grammar_failure_point(gbnf: &gbnf_validator::Validator, grammar: &str, text: &str) { |
| 93 | + use colored::Colorize; |
| 94 | + |
| 95 | + for length in 1..=text.len() { |
| 96 | + let substring = &text[0..length]; |
| 97 | + let current_char = text.chars().nth(length - 1).unwrap(); |
| 98 | + |
| 99 | + match gbnf.validate(grammar, substring) { |
| 100 | + Ok(true) => print!("{}", current_char.to_string().green()), |
| 101 | + Ok(false) => print!("{}", current_char.to_string().red()), |
| 102 | + Err(_) => print!("{}", current_char.to_string().yellow()), |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments