Last active
November 23, 2017 21:09
-
-
Save thbar/7354ee89c88d56d06d7b4e6a4d37677e to your computer and use it in GitHub Desktop.
Calling a Rust crate from Ruby minitest
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
| require_relative 'test_helper' | |
| require 'helix_runtime' | |
| require 'etl-test/native' | |
| class MyTest < Minitest::Test | |
| def test_valid | |
| assert_equal true, IbanChecker.check('TL380080012345678910157') | |
| end | |
| def test_invalid_country | |
| assert_equal false, IbanChecker.check('AD54BD012030200359100100') | |
| end | |
| def test_invalid_length | |
| assert_equal false, IbanChecker.check('DE4') | |
| end | |
| end |
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
| #[macro_use] | |
| extern crate helix; | |
| extern crate iban; | |
| use std::str; | |
| use iban::Iban; | |
| use iban::BbanResult; | |
| ruby! { | |
| class IbanChecker { | |
| def check(iban_number : String) -> bool { | |
| let account = iban_number.parse::<Iban>(); | |
| let account = match account { | |
| Ok(iban) => iban, | |
| Err(_error) => { | |
| return false; | |
| } | |
| }; | |
| if account.validate_bban() == BbanResult::Valid { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment