Skip to content

Commit 69ca634

Browse files
authored
add tests for bar trace (#82)
1 parent 0dad1bc commit 69ca634

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

plotly/src/bar.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,90 @@ where
303303
serde_json::to_string(&self).unwrap()
304304
}
305305
}
306+
307+
#[cfg(test)]
308+
mod tests {
309+
use serde_json::{json, to_value};
310+
311+
use crate::common::ErrorType;
312+
313+
use super::*;
314+
315+
#[test]
316+
fn test_serialize_bar() {
317+
let bar = Bar::new(vec![1, 2], vec![3, 4])
318+
.name("Bar")
319+
.visible(Visible::LegendOnly)
320+
.show_legend(false)
321+
.legend_group("legend-group")
322+
.opacity(0.5)
323+
.ids(vec!["1"])
324+
.width(999)
325+
.offset(5)
326+
.offset_array(vec![5, 5])
327+
.text("text")
328+
.text_array(vec!["text"])
329+
.text_position(TextPosition::None)
330+
.text_position_array(vec![TextPosition::None])
331+
.text_template("text_template")
332+
.text_template_array(vec!["text_template"])
333+
.hover_text("hover_text")
334+
.hover_text_array(vec!["hover_text"])
335+
.x_axis("xaxis")
336+
.y_axis("yaxis")
337+
.orientation(Orientation::Vertical)
338+
.alignment_group("alignment_group")
339+
.offset_group("offset_group")
340+
.marker(Marker::new())
341+
.text_angle(0.05)
342+
.text_font(Font::new())
343+
.error_x(ErrorData::new(ErrorType::Constant))
344+
.error_y(ErrorData::new(ErrorType::Percent))
345+
.clip_on_axis(true)
346+
.constrain_text(ConstrainText::Both)
347+
.hover_label(Label::new())
348+
.inside_text_anchor(TextAnchor::End)
349+
.inside_text_font(Font::new())
350+
.outside_text_font(Font::new())
351+
.x_calendar(Calendar::Nanakshahi)
352+
.y_calendar(Calendar::Ummalqura);
353+
354+
let expected = json!({
355+
"type": "bar",
356+
"x": [1, 2],
357+
"y": [3, 4],
358+
"name": "Bar",
359+
"visible": "legendonly",
360+
"showlegend": false,
361+
"legendgroup": "legend-group",
362+
"opacity": 0.5,
363+
"ids": ["1"],
364+
"width": 999,
365+
"offset": [5, 5],
366+
"text": ["text"],
367+
"textposition": ["none"],
368+
"texttemplate": ["text_template"],
369+
"hovertext": ["hover_text"],
370+
"xaxis": "xaxis",
371+
"yaxis": "yaxis",
372+
"orientation": "v",
373+
"alignmentgroup": "alignment_group",
374+
"offsetgroup": "offset_group",
375+
"marker": {},
376+
"textangle": 0.05,
377+
"textfont": {},
378+
"error_x": {"type": "constant"},
379+
"error_y": {"type": "percent"},
380+
"cliponaxis": true,
381+
"constraintext": "both",
382+
"hoverlabel": {},
383+
"insidetextanchor": "end",
384+
"insidetextfont": {},
385+
"outsidetextfont": {},
386+
"xcalendar": "nanakshahi",
387+
"ycalendar": "ummalqura",
388+
});
389+
390+
assert_eq!(to_value(bar).unwrap(), expected);
391+
}
392+
}

0 commit comments

Comments
 (0)