Skip to content

Instantly share code, notes, and snippets.

@ginowu7
Created February 8, 2019 17:00
Show Gist options
  • Save ginowu7/00f66c9f08d5657c64d166abcae77a55 to your computer and use it in GitHub Desktop.
Save ginowu7/00f66c9f08d5657c64d166abcae77a55 to your computer and use it in GitHub Desktop.
Parsing comment blocks for AB_TEST
func validateABTests(file: String) {
let declaredVariantFile = findPath(file)
let variantContents = contents(atPath: declaredVariantFile)
let variantTests = regexFor("(.*//\\s*AB_TEST.*)", content: variantContents)
variantTests.forEach {
guard let expirationDateSerialized = regexFor("((0|1)\\d{1})/((0|1|2)\\d{1})/((19|20)\\d{2})", content: $0).first,
let expirationDate = dateFormatter.date(from: expirationDateSerialized) else {
fatalError("Incorrect expiration date format: MM/dd/yyyy")
}
if let expiredTest = regexFor(".+?(?=:)", content: $0).first, expirationDate < currentDate {
print("warning: \(expiredTest) AB Test is expired - \n:\($0)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment