Skip to content

Conform Semver and Range to fmt::Display #10

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

Merged
merged 8 commits into from
Jan 5, 2025
Merged

Conversation

mxcl
Copy link
Contributor

@mxcl mxcl commented Jan 3, 2025

I imagine this is horrendous and maybe even dangerous.

It also isn’t quite how libpkgx behaves since we keep a “pretty” string around for rendering purposes but let’s find out if we need that later.

@mxcl mxcl changed the title Confirm Semver and Range to fmt::Display Conform Semver and Range to fmt::Display Jan 3, 2025
@mxcl
Copy link
Contributor Author

mxcl commented Jan 3, 2025

Also you may want to put the code in different files? I tried, but cargo complained.

@mxcl
Copy link
Contributor Author

mxcl commented Jan 3, 2025

Also I'm assuming you want these, but you don’t have to.

@jhheider
Copy link
Owner

jhheider commented Jan 3, 2025

i want this a lot. i just need to add tests so coveralls doesn't make me look bad.

not presently working, because i don't understand the code in `at()`
@mxcl
Copy link
Contributor Author

mxcl commented Jan 3, 2025

Since we're rendering @ here perhaps we should properly support @ in Range::parse too? I can add that in a separate PR.

and make it easy to run with docker
@jhheider
Copy link
Owner

jhheider commented Jan 4, 2025

ok, I think I solved it. @ is =:

import SemVer, { Range } from "./src/utils/semver.ts";

const a = new SemVer("1.2.3")!;
const b = new SemVer("1.2.4")!;
const r = new Range([[a, b]]);

console.log("a:", a);
console.log("b:", b);
console.log("r:", r);

[1.2, 1.3] isn't @1.2, but [1.2.2.2, 1.2.2.3] is @1.2.2.2..... sooooo, ok.

Copy link
Owner

@jhheider jhheider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mxcl: please confirm this conforms to your understanding of @:

#[test]
fn test_at() -> Result<()> {
    let ra = Range::parse(">=1.0<1.1")?;

    assert_eq!(format!("{ra}"), "~1");

    let rb = Range::parse("=1.1")?;

    assert_eq!(format!("{rb}"), "=1.1");

    let rc = Range::parse(">=1.1.0<1.1.1")?;

    assert_eq!(format!("{rc}"), "@1.1.0");

    let rd = Range::parse("=1.1.1")?;

    assert_eq!(format!("{rd}"), "=1.1.1");

    let re = Range::parse(">=1.1.1.0<1.1.1.1")?;

    assert_eq!(format!("{re}"), "@1.1.1.0");

    let rf = Range::parse("=1.1.1.0")?;

    assert_eq!(format!("{rf}"), "=1.1.1.0");

    let rg = Range::parse(">=1.1<1.1.1.1.1")?;

    assert_eq!(format!("{rg}"), ">=1.1<1.1.1.1.1");

    let rh = Range::parse(">=1.1.1<1.1.3")?;

    assert_eq!(format!("{rh}"), ">=1.1.1<1.1.3");

    let ri = Range::parse(">=1.1.1<1.2.2")?;

    assert_eq!(format!("{ri}"), ">=1.1.1<1.2.2");

    Ok(())
}

@jhheider
Copy link
Owner

jhheider commented Jan 4, 2025

Since we're rendering @ here perhaps we should properly support @ in Range::parse too? I can add that in a separate PR.

went ahead here: 454ad14

@coveralls
Copy link

Pull Request Test Coverage Report for Build 12613833404

Details

  • 60 of 60 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+2.1%) to 99.355%

Totals Coverage Status
Change from base Build 12613825016: 2.1%
Covered Lines: 308
Relevant Lines: 310

💛 - Coveralls

@mxcl
Copy link
Contributor Author

mxcl commented Jan 5, 2025

Yes this is correct IMO. Thank you!

@jhheider jhheider merged commit 0331a9e into jhheider:main Jan 5, 2025
7 checks passed
@mxcl mxcl deleted the fmt_display branch January 5, 2025 18:48
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