test_init.rs
1 use crate::{ 2 item::{ 3 attr::{AttrIndexes, AttrSpecificData, ItemAttrs}, 4 image::ItemImages, 5 spec::ItemSpecs, 6 }, 7 Item, Market, Store, Tag, ITEMS, MARKETS, STORES, TAGS, 8 }; 9 use interface::{ 10 item::{attr::AttrKeys, ItemCoreKeys}, 11 unit::Currency, 12 }; 13 14 pub fn test_init() { 15 let items = [Item { 16 name: "Polaroid OneStep 2".to_string(), 17 descriptions: vec![ 18 "ポラロイドカメラ。".to_string(), 19 "古くて新鮮なカメラで日常の一瞬を切り取る。".to_string(), 20 ], 21 store_id: 1, 22 tag_ids: vec![1, 2], 23 images: ItemImages::new_str( 24 vec![ 25 ("https://images.unsplash.com/photo-1526170375885-4d8ecf77b99f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2370&q=80", "Polaroid OneStep 2, seen from the front in its black-and-white casing, allows users to immediately print out the photos they have taken."), 26 ("https://images.unsplash.com/photo-1547022188-a8c4136f649b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2515&q=80", "The design is reminiscent of the original OneStep and is packed with easy-to-use features."), 27 ("https://images.unsplash.com/photo-1526170160160-1a5eb242ab58?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "White and black Polaroid instant camera beside books."), 28 ("https://images.unsplash.com/photo-1526170286768-b3c80b34b036?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "With Impossible color instant films."), 29 ("https://images.unsplash.com/photo-1545155085-967cb231d65f?q=80&w=2784&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "Polaroid OneStep 2"), 30 ], 31 vec![ 32 vec![0, 1, 2, 3, 4] 33 ] 34 ), 35 specs: ItemSpecs::new_str( 36 vec![ 37 ( 38 "Size", 39 vec![ 40 ("Height", vec![vec!["12cm"]]), 41 ("Width", vec![vec!["12cm"]]), 42 ("Depth", vec![vec!["17.3cm"]]), 43 ] 44 ), 45 ], 46 vec![ 47 (0, vec![(0, 0), (1, 0), (2, 0)]), 48 ] 49 ), 50 attrs: ItemAttrs::new( 51 AttrSpecificData { 52 stock: 10, 53 price: vec![(Currency::USD, 99.5), (Currency::JPY, 10000 as f64)].into_iter().collect(), 54 image_vec_key: 0, 55 spec_keys: vec![0], 56 sale: (), 57 }, 58 AttrIndexes { 59 attr1: None, 60 attr2: None, 61 attr3: None, 62 attr4: None, 63 } 64 ) 65 },Item { 66 name: "The Baseball Cap".to_string(), 67 descriptions: vec![ 68 "カジュアルな場に最適なベースボールキャップ。".to_string(), 69 ], 70 store_id: 1, 71 tag_ids: vec![1, 2], 72 images: ItemImages::new_str( 73 vec![ 74 ("https://images.unsplash.com/photo-1519079754742-f83afaef6d35?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "Polaroid OneStep 2, seen from the front in its black-and-white casing, allows users to immediately print out the photos they have taken."), 75 ("https://images.unsplash.com/photo-1645266729222-17cd32e06fd0?q=80&w=2670&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "The design is reminiscent of the original OneStep and is packed with easy-to-use features."), 76 ("https://images.unsplash.com/photo-1466992133056-ae8de8e22809?q=80&w=2847&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "White and black Polaroid instant camera beside books."), 77 ], 78 vec![ 79 vec![0], 80 vec![1], 81 vec![2], 82 ] 83 ), 84 specs: ItemSpecs::new_str( 85 vec![ 86 ( 87 "Size", 88 vec![ 89 ("Height", vec![vec!["12cm"]]), 90 ("Width", vec![vec!["12cm"]]), 91 ("Depth", vec![vec!["17.3cm"]]), 92 ] 93 ), 94 ], 95 vec![ 96 (0, vec![(0, 0), (1, 0), (2, 0)]), 97 ] 98 ), 99 attrs: ItemAttrs::new( 100 AttrSpecificData { 101 stock: 10, 102 price: vec![(Currency::USD, 99.5), (Currency::JPY, 10000 as f64)].into_iter().collect(), 103 image_vec_key: 0, 104 spec_keys: vec![0], 105 sale: (), 106 }, 107 AttrIndexes { 108 attr1: None, 109 attr2: None, 110 attr3: None, 111 attr4: None, 112 } 113 ) 114 }]; 115 116 let stores = [Store { 117 name: "Specimens".to_string(), 118 stocked_items: vec![1], 119 }]; 120 121 let markets = [ 122 Market::new( 123 "Delighted Cameras".to_string(), 124 Some(vec![ItemCoreKeys { 125 item_id: 1, 126 attr_keys: AttrKeys::default(), 127 }]), 128 ), 129 Market::new( 130 "Specimens Authorized".to_string(), 131 Some(vec![ 132 ItemCoreKeys { 133 item_id: 1, 134 attr_keys: AttrKeys::default(), 135 }, 136 ItemCoreKeys { 137 item_id: 2, 138 attr_keys: AttrKeys::default(), 139 }, 140 ]), 141 ), 142 ]; 143 144 let tags = [ 145 Tag { 146 name: "camera".to_string(), 147 tagged_items: vec![1], 148 tagged_markets: vec![], 149 }, 150 Tag { 151 name: "polaroid".to_string(), 152 tagged_items: vec![1], 153 tagged_markets: vec![], 154 }, 155 Tag { 156 name: "cap".to_string(), 157 tagged_items: vec![2], 158 tagged_markets: vec![], 159 }, 160 ]; 161 162 items.iter().enumerate().for_each(|(i, item)| { 163 ITEMS.with(|p| p.borrow_mut().insert(i as u128 + 1, item.clone())); 164 }); 165 166 stores.iter().enumerate().for_each(|(i, store)| { 167 STORES.with(|p| p.borrow_mut().insert(i as u128 + 1, store.clone())); 168 }); 169 170 markets.iter().enumerate().for_each(|(i, market)| { 171 MARKETS.with(|p| p.borrow_mut().insert(i as u128 + 1, market.clone())); 172 }); 173 174 tags.iter().enumerate().for_each(|(i, tag)| { 175 TAGS.with(|p| p.borrow_mut().insert(i as u128 + 1, tag.clone())); 176 }); 177 }