Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TemplateElement's source field type from String to SourceString #3677

Merged

Conversation

jcamiel
Copy link
Collaborator

@jcamiel jcamiel commented Jan 31, 2025

This PR change TemplateElement's source field type from String to SourceString

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TemplateElement {
    String { value: String, source: SourceString },
    Placeholder(Placeholder),
}

A newtype new struct SourceString is introduced in core::typing and the methods to seamlessly work with String &str etc...

Note

Not sure if typing is the best module name (it's model on Python). This module contains "common" types for Hurl's crates. Maybe we should change it from typing to types?

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct SourceString(String);

impl SourceString {
    /// Creates a new empty [`SourceString`].
    pub fn new() -> Self {
        SourceString(String::new())
    }

    /// Appends a given string slice onto the end of this [`SourceString`].
    pub fn push_str(&mut self, string: &str) {
        self.0.push_str(string);
    }

    /// Appends the given char to the end of this [`SourceString`].
    pub fn push(&mut self, c: char) {
        self.0.push(c);
    }

    /// Extracts a string slice containing the entire [`SourceString`].
    pub fn as_str(&self) -> &str {
        self.0.as_str()
    }

    /// Returns `true` if this [`SubString`] starts with the char `c`.
    pub fn starts_with(&self, c: char) -> bool {
        self.0.starts_with(c)
    }
}

pub trait ToSource {
    fn to_source(&self) -> SourceString;
}

impl<T> ToSource for T
where
    T: AsRef<str>,
{
    fn to_source(&self) -> SourceString {
        SourceString(self.as_ref().to_string())
    }
}

impl<T> From<T> for SourceString
where
    T: AsRef<str>,
{
    fn from(value: T) -> Self {
        SourceString(value.as_ref().to_string())
    }
}

impl fmt::Display for SourceString {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.0)
    }
}

Rest of the code is updating unit tests.

@jcamiel jcamiel self-assigned this Jan 31, 2025
@jcamiel jcamiel force-pushed the change-template-element-source-filed-type-to-source-string branch 2 times, most recently from 7e0f878 to 508deb2 Compare January 31, 2025 10:50
@jcamiel jcamiel requested a review from fabricereix January 31, 2025 11:25
@jcamiel
Copy link
Collaborator Author

jcamiel commented Jan 31, 2025

/rebase

@hurl-bot
Copy link
Collaborator

🕗 /rebase is running, please wait for completion.

@hurl-bot
Copy link
Collaborator

🔨 Auto rebase from Orange-OpenSource/hurl/master succeeds, Orange-OpenSource/hurl/change-template-element-source-filed-type-to-source-string now embeds these commits:

  • 0887fcb Make Float field provate (like I64 et U64).
  • 583cf90 Implement functions with Value

@hurl-bot hurl-bot force-pushed the change-template-element-source-filed-type-to-source-string branch from 508deb2 to 5428dec Compare January 31, 2025 13:22
fabricereix
fabricereix previously approved these changes Jan 31, 2025
@jcamiel jcamiel force-pushed the change-template-element-source-filed-type-to-source-string branch from 5428dec to c58bf74 Compare January 31, 2025 15:06
@jcamiel
Copy link
Collaborator Author

jcamiel commented Jan 31, 2025

/accept

@hurl-bot
Copy link
Collaborator

🕗 /accept is running, please wait for completion.

@hurl-bot
Copy link
Collaborator

🔨 Auto rebase from Orange-OpenSource/hurl/master succeeds, Orange-OpenSource/hurl/change-template-element-source-filed-type-to-source-string now embeds these commits:

  • bcbdbd6 Support BigInteger in variable
  • a5fae91 Remove cloning on AST request helpers.
  • 07745d3 Update documentation for base64Encode filter
  • 7c42440 Update documentation for base64 filter

@hurl-bot
Copy link
Collaborator

🕗 /accept is still running, please wait for completion.

@hurl-bot hurl-bot force-pushed the change-template-element-source-filed-type-to-source-string branch from c58bf74 to 3f3f9e9 Compare January 31, 2025 17:12
@hurl-bot
Copy link
Collaborator

✅ Pull request merged with fast forward by jcamiel..

# List of commits merged from Orange-OpenSource/hurl/change-template-element-source-filed-type-to-source-string branch into Orange-OpenSource/hurl/master branch:

  • 3f3f9e9 Change TemplateElement's source field type from String to SourceString.

@hurl-bot hurl-bot merged commit 3f3f9e9 into master Jan 31, 2025
25 checks passed
@hurl-bot hurl-bot deleted the change-template-element-source-filed-type-to-source-string branch January 31, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants