Created
May 3, 2013 08:46
-
-
Save melwil/5508003 to your computer and use it in GitHub Desktop.
Small test suite for BASE64 regex.
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 TestBASE64 { | |
public static void main(String[]a) { | |
String regex = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$"; | |
String[] test = { | |
"TWFu", | |
"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=", | |
"YW55IGNhcm5hbCBwbGVhc3VyZS4=", | |
"YW55IGNhcm5hbCBwbGVhc3VyZQ==", | |
"YW55IGNhcm5hbCBwbGVhc3Vy", | |
"YW55IGNhcm5hbCBwbGVhc3U=", | |
"YW55IGNhcm5hbCBwbGVhcw==", | |
}; | |
boolean success = true; | |
for (String s : test) { | |
if (!s.matches(regex)) success = false; | |
} | |
System.out.println("Tests conclude that regex matches all BASE64 examples? "+success); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment