Skip to content

Commit

Permalink
Add ToStringAndBack test along with many of new ops
Browse files Browse the repository at this point in the history
  • Loading branch information
hextriclosan committed Oct 23, 2024
1 parent 1ce533b commit c18374e
Show file tree
Hide file tree
Showing 7 changed files with 529 additions and 4 deletions.
12 changes: 12 additions & 0 deletions tests/should_convert_to_string_and_back.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod utils;
use crate::utils::get_long;
use utils::setup;

#[test]
fn should_convert_to_string_and_back() {
let mut vm = setup();
let last_frame_value = vm
.run("samples.javacore.strings.trivial.ToStringAndBack")
.unwrap();
assert_eq!(1002000033239, get_long(last_frame_value))
}
65 changes: 65 additions & 0 deletions tests/test_data/ToStringAndBack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package samples.javacore.strings.trivial;

public class ToStringAndBack {

public static void main(String[] args) {
boolean convertedBoolean = convertBoolean();
byte convertedByte = convertByte();
short convertedShort = convertShort();
char convertedChar = convertChar();
int convertedInt = convertInt();
long convertedLong = convertLong();
float convertedFloat = convertFloat();
double convertedDouble = 0;//convertDouble(); fixme: freezes after WIDE ops

long result = (convertedBoolean ? 1 : 0) + convertedByte + convertedShort + convertedChar + convertedInt + convertedLong + (long) convertedFloat + (long) convertedDouble;
}

private static boolean convertBoolean() {
boolean value = true;
String string = Boolean.toString(value);
return Boolean.parseBoolean(string);
}

private static byte convertByte() {
byte value = 127;
String string = Byte.toString(value);
return Byte.parseByte(string);
}

private static short convertShort() {
short value = 31999;
String string = Short.toString(value);
return Short.parseShort(string);
}

private static char convertChar() {
char value = 'ї';
String string = Character.toString(value);
return string.charAt(0);
}

private static int convertInt() {
int value = 1_999_999_999;
String string = Integer.toString(value);
return Integer.parseInt(string);
}

private static long convertLong() {
long value = 999_999_999_999L;
String string = Long.toString(value);
return Long.parseLong(string);
}

private static double convertDouble() {
double value = 3.14;
String string = Double.toString(value);
return Double.parseDouble(string);
}

private static float convertFloat() {
float value = 3.14f;
String string = Float.toString(value);
return Float.parseFloat(string);
}
}
Binary file not shown.
Loading

0 comments on commit c18374e

Please sign in to comment.