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
| fn load_and_validate(max: usize) -> Result<Vec<Feature>, String> { | |
| let raw: Vec<Result<Feature, Error>> = load_features_from_db(); | |
| if raw.len() > max { | |
| return Err(format!( | |
| "too many features: {} > {}", | |
| raw.len(), max | |
| )); | |
| } | |
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
| let features: Vec<Feature> = load_features_from_db(); | |
| let max = 200; | |
| assert!(features.len() <= max); | |
| # This magic number assumption | |
| # is actually wrong | |
| for f in features { | |
| proxy.add_bot_feature(f.unwrap()); | |
| # You also call unwrap() on every feature. | |
| # If the database returns an invalid entry |
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
| public class QueryBuilder { | |
| public String buildEmployeeQuery() { | |
| // 1. Identify multi-line string concatenations or strings | |
| // with excessive escape sequences | |
| // 2. Replace opening quote and concatenation operators | |
| // with triple quotes (""") | |
| // 3. Remove escape sequences for quotes and newlines | |
| // 4. Adjust indentation to match your code style | |
| // 5. Add .strip() for single-line regex patterns or | |
| // when trailing newlines cause issues |
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
| public class QueryBuilder { | |
| public String buildEmployeeQuery() { | |
| String sql = "SELECT emp.employee_id, " + | |
| "emp.first_name, emp.last_name, " + | |
| " dept.department_name, " + | |
| "emp.salary " + | |
| "FROM employees emp " + | |
| "JOIN departments dept ON " + | |
| "emp.department_id = " + | |
| "dept.department_id " + |
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
| movie.rate.warnIfNotAllowed(this.age); |
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
| function testFalse() | |
| { | |
| Assert(1==2) | |
| } |
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
| forRecipients: recipients | |
| recipients do: [:eachAddress | | |
| eachAddress isString | |
| ifFalse: [ | |
| self error: (eachAddress , ' is not a valid recipient')] ]. | |
| (recipients asSet size = recipients size) | |
| ifFalse: [ | |
| self error: 'Duplicates']. | |
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
| test07SimpleScenarios | |
| self assert: | |
| (EmailMessage forRecipients: | |
| (Array with: '[email protected]')) plain = 'to: [email protected]' |
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
| forRecipients: recipients | |
| self assertAllAddressesAreValid: recipients. | |
| self assertThereAreNoDuplicates: recipients. | |
| ^self new initializeForRecipients: recipients |
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
| test06ExceptionalBehavior | |
| self | |
| should: | |
| [EmailMessage | |
| forRecipients: | |
| (Array with: '[email protected]' with: '[email protected]')] | |
| raise: Exception |
NewerOlder