about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCarl-Anton Ingmarsson <mail@carlanton.se>2014-01-12 12:50:01 +0100
committerCarl-Anton Ingmarsson <mail@carlanton.se>2014-01-12 13:33:52 +0100
commit1130886138f1dc6285ac2011c6bcabefd564bb7d (patch)
tree650bd7149e01876bd6cc59374178e95bfa3559af
parente9b188a590cbfad840126ecad131eaa718ce6f5f (diff)
downloadrust-1130886138f1dc6285ac2011c6bcabefd564bb7d.tar.gz
rust-1130886138f1dc6285ac2011c6bcabefd564bb7d.zip
extra::ebml: Add unit test for vuint_at()
-rw-r--r--src/libextra/ebml.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs
index e3a05ae0960..4449de342d7 100644
--- a/src/libextra/ebml.rs
+++ b/src/libextra/ebml.rs
@@ -939,6 +939,54 @@ mod tests {
     use std::option::{None, Option, Some};
 
     #[test]
+    fn test_vuint_at() {
+        let data = [
+            0x80,
+            0xff,
+            0x40, 0x00,
+            0x7f, 0xff,
+            0x20, 0x00, 0x00,
+            0x3f, 0xff, 0xff,
+            0x10, 0x00, 0x00, 0x00,
+            0x1f, 0xff, 0xff, 0xff
+        ];
+
+        let mut res: reader::Res;
+
+        // Class A
+        res = reader::vuint_at(data, 0);
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 1);
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, (1 << 7) - 1);
+        assert_eq!(res.next, 2);
+
+        // Class B
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 4);
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, (1 << 14) - 1);
+        assert_eq!(res.next, 6);
+
+        // Class C
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 9);
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, (1 << 21) - 1);
+        assert_eq!(res.next, 12);
+
+        // Class D
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, 0);
+        assert_eq!(res.next, 16);
+        res = reader::vuint_at(data, res.next);
+        assert_eq!(res.val, (1 << 28) - 1);
+        assert_eq!(res.next, 20);
+    }
+
+    #[test]
     fn test_option_int() {
         fn test_v(v: Option<int>) {
             debug!("v == {:?}", v);