Skip to content

Instantly share code, notes, and snippets.

@thbar
Last active November 23, 2017 21:09
Show Gist options
  • Select an option

  • Save thbar/7354ee89c88d56d06d7b4e6a4d37677e to your computer and use it in GitHub Desktop.

Select an option

Save thbar/7354ee89c88d56d06d7b4e6a4d37677e to your computer and use it in GitHub Desktop.
Calling a Rust crate from Ruby minitest
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
#[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