Unexpected panic comparing two Strings

Running the following test…

#[test]   
fn convertFromHexToDec_() {
        let input = "0123456789abcdef";    //  81985529216486895 in decimal
        let fromBase = 16u8;
        let toBase = 10u8;
        let result = convertBase(input, fromBase, toBase); 
        println!("{} len:{}",result, result.len());    //prints: 81985529216486895 len:17  
        let expResult = "81985529216486895‬";
        println!("{} len:{}",expResult, expResult.len()); //prints: 81985529216486895 len:20
        assert_eq!(expResult, result);
   }

… I get an unexpected message. The cause is not the result of my (correct) function I am testing here but the unexpected modification of the &str on the left side of assert_eq:

        panics with this message:
        thread 'HexToDecString::tests::convertBase_test2' panicked at 'assertion failed: `(left == right)`
        left: `"81985529216486895\u{202c}"`,
        right: `"81985529216486895"`'
The same problem with expResult.to_string() or comparing format!("{}", expResult) with the result.
Once I got this message:
        left: `"\u{202d}81985529216486895\u{202c}"`,

Where do the unicode characters u+202d and u+202c “left-to-right-override” and “pop directional formatting” come from? It seems that assert_eq! adds them to the &str on the left side.

Any ideas?

I am using IntelliJ 2019.1.2 (last updated today), with the latest stable rust version.

Welcome to Rust!

To make your post more readable, please post your code inside of code fences

```rust
// rust code here
```
Not rust code, but also needs to be formatted (example panic messages)
```
in here
```
or if you want it inline, do `inline formatting`

and you will see

or if you want it inline, do inline formatting


Without knowing what convertBase does, we can’t say anything to help

2 Likes

They will be in your source file. Just editors don’t show non printable characters. Maybe you pasted the string from somewhere else.

1 Like

jonh, thank you very much. That is the solution! I copied it from a calculator!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.