From d3da25131c41fedd8739b60cb64cce3cbf8e663e Mon Sep 17 00:00:00 2001 From: Chad Stearns Date: Sun, 15 Nov 2020 21:36:16 -0500 Subject: [PATCH] In small_str test helper function, dont use the hard coded value of 16, use the actual size of the RocStr memory footprint --- compiler/gen/tests/gen_str.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/gen/tests/gen_str.rs b/compiler/gen/tests/gen_str.rs index 6e2b76a2f1..8f90bc464c 100644 --- a/compiler/gen/tests/gen_str.rs +++ b/compiler/gen/tests/gen_str.rs @@ -8,32 +8,38 @@ extern crate inkwell; extern crate libc; extern crate roc_gen; +use core; +use roc_std::RocStr; + #[macro_use] mod helpers; +const ROC_STR_MEM_SIZE: usize = core::mem::size_of::(); + #[cfg(test)] mod gen_str { + use crate::ROC_STR_MEM_SIZE; use std::cmp::min; - fn small_str(str: &str) -> [u8; 16] { - let mut bytes: [u8; 16] = Default::default(); + fn small_str(str: &str) -> [u8; ROC_STR_MEM_SIZE] { + let mut bytes: [u8; ROC_STR_MEM_SIZE] = Default::default(); let mut index: usize = 0; - while index < 16 { + while index < ROC_STR_MEM_SIZE { bytes[index] = 0; index += 1; } let str_bytes = str.as_bytes(); - let output_len: usize = min(str_bytes.len(), 16); + let output_len: usize = min(str_bytes.len(), ROC_STR_MEM_SIZE); index = 0; while index < output_len { bytes[index] = str_bytes[index]; index += 1; } - bytes[15] = 0b1000_0000 ^ (output_len as u8); + bytes[ROC_STR_MEM_SIZE - 1] = 0b1000_0000 ^ (output_len as u8); bytes }