1#![allow(dead_code)]
2#![allow(unused_variables)]
3use std::str::FromStr;
30
31use serde::{Deserialize, Serialize};
32
33type HighlightGroup = String;
34
35#[derive(Serialize, Deserialize)]
37pub struct TextProperty {
38 pub id: i32,
39 pub r#type: String,
40}
41
42#[derive(Default, Serialize, Deserialize)]
44pub struct PropertyType {
45 highlight: Option<HighlightGroup>,
46 combine: Option<bool>,
47 priority: Option<i32>,
48 start_include: Option<bool>,
49 end_include: Option<bool>,
50}
51
52impl FromStr for PropertyType {
54 type Err = serde_json::Error;
55
56 fn from_str(s: &str) -> Result<Self, Self::Err> {
57 serde_json::from_str(s)
58 }
59}
60
61#[derive(Default)]
62pub struct PropertyTypeBuilder {
63 highlight: Option<HighlightGroup>,
64 combine: Option<bool>,
65 priority: Option<i32>,
66 start_include: Option<bool>,
67 end_include: Option<bool>,
68}
69
70impl PropertyTypeBuilder {
71 pub fn build(self) -> PropertyType {
72 PropertyType {
73 highlight: self.highlight,
74 combine: self.combine,
75 priority: self.priority,
76 start_include: self.start_include,
77 end_include: self.end_include,
78 }
79 }
80}
81
82impl PropertyTypeBuilder {
83 pub fn highlight(mut self, highlight: HighlightGroup) -> Self {
84 self.highlight = Some(highlight);
85 self
86 }
87 pub fn combine(mut self, combine: bool) -> Self {
88 self.combine = Some(combine);
89 self
90 }
91 pub fn priority(mut self, priority: i32) -> Self {
92 self.priority = Some(priority);
93 self
94 }
95 pub fn start_include(mut self, start_include: bool) -> Self {
96 self.start_include = Some(start_include);
97 self
98 }
99 pub fn end_include(mut self, end_include: bool) -> Self {
100 self.end_include = Some(end_include);
101 self
102 }
103}
104
105mod tests {
106 use super::*;
107
108 #[test]
109 fn test_property_type() {
110 let pt = PropertyType {
111 highlight: Some("Constant".to_string()),
112 combine: Some(true),
113 priority: Some(-10),
114 start_include: Some(true),
115 end_include: Some(true),
116 };
117 assert_eq!(pt.highlight, Some("Constant".to_string()));
118 assert_eq!(pt.combine, Some(true));
119 assert_eq!(pt.priority, Some(-10));
120 assert_eq!(pt.start_include, Some(true));
121 assert_eq!(pt.end_include, Some(true));
122 }
123 #[test]
124 fn test_property_type_empty() {
125 let pt: PropertyType = Default::default();
126 assert_eq!(pt.highlight, None);
127 assert_eq!(pt.combine, None);
128 assert_eq!(pt.priority, None);
129 assert_eq!(pt.start_include, None);
130 assert_eq!(pt.end_include, None);
131 }
132 #[test]
133 fn test_property_type_builder() {
134 let pt = PropertyTypeBuilder::default()
135 .highlight("Constant".to_string())
136 .build();
137 assert_eq!(pt.highlight, Some("Constant".to_string()));
138 }
139}